zoukankan      html  css  js  c++  java
  • duilib进阶教程 -- Label控件的bug (8)

      上个教程说到了TreeView的文字不能垂直居中的问题,而我们用LabelUI其实是可以垂直居中的,为什么不说是TreeView的bug,而说是Label控件的bug呢?因为影响TreeView垂直居中的就是Label,可以发现LabelUI的【属性列表.XML】里有valign属性,而代码里却找不到,是因为valign属性被合并到align属性里去了,只要设置align="center"就可以水平垂直都居中,但是想要垂直居中,水平左对齐啥的,就犯难了,因此这里需要将两个属性分开,valign管垂直,align管水平,这样想要怎么组合都OK啦。

      将CLabelUI::SetAttribute函数里if( _tcscmp(pstrName, _T("align")) == 0 ) 那一段代码改成下面这样即可。(记得重新编译duilib哦~)

            if( _tcscmp(pstrName, _T("align")) == 0 ) {
                if( _tcsstr(pstrValue, _T("left")) != NULL ) {
                    m_uTextStyle &= ~(DT_CENTER | DT_RIGHT | DT_SINGLELINE);
                    m_uTextStyle |= DT_LEFT;
                }
                if( _tcsstr(pstrValue, _T("center")) != NULL ) {
                    m_uTextStyle &= ~(DT_LEFT | DT_RIGHT );
                    m_uTextStyle |= DT_CENTER;
                }
                if( _tcsstr(pstrValue, _T("right")) != NULL ) {
                    m_uTextStyle &= ~(DT_LEFT | DT_CENTER | DT_SINGLELINE);
                    m_uTextStyle |= DT_RIGHT;
                }
            }
            else if( _tcscmp(pstrName, _T("valign")) == 0 ) {
                if( _tcsstr(pstrValue, _T("top")) != NULL ) {
                    m_uTextStyle &= ~(DT_BOTTOM | DT_VCENTER);
                    m_uTextStyle |= (DT_TOP | DT_SINGLELINE);
                }
                if( _tcsstr(pstrValue, _T("vcenter")) != NULL ) {
                    m_uTextStyle &= ~(DT_TOP | DT_BOTTOM );            
                    m_uTextStyle |= (DT_VCENTER | DT_SINGLELINE);
                }
                if( _tcsstr(pstrValue, _T("bottom")) != NULL ) {
                    m_uTextStyle &= ~(DT_TOP | DT_VCENTER);
                    m_uTextStyle |= (DT_BOTTOM | DT_SINGLELINE);
                }
            }

      嗯,实现了垂直居中的效果后,现在貌似和迅雷一模一样啦?

      NO,NO,NO,下一节将会继续介绍~O(∩_∩)O~





  • 相关阅读:
    2016第34周三
    2016第34周二
    Spring中资源的加载ResourceLoader
    Spring的资源抽象Resource2实体类
    Spring资源抽象Resource
    SQL Server死锁产生原因及解决办法 .
    sql server中同时执行select和update语句死锁问题
    数据库死锁实例分析及解决方法
    一次查找sqlserver死锁的经历
    js和Jquery获取选中select值和文本
  • 原文地址:https://www.cnblogs.com/Alberl/p/3403070.html
Copyright © 2011-2022 走看看