扩展duilib edit控件的提示功能和多种文字颜色(解决edit为password显示不正常的bug)

参考博客:Redrain

转载:http://blog.csdn.net/zhuhongshu/article/details/41786407

在Redrain博客的基础上做了修改

1.CEditUI的DoEvent函数添加一下代码

 1 /////////////////////////
 2 if( event.Type == UIEVENT_SETFOCUS && IsEnabled() ) 
 3     {
 4         if (_tcscmp(GetText(),GetSrcTipValue()) != 0)
 5         {
 6             SetText(GetText());//说明用户有输入,显示用户输入
 7         }
 8         else
 9         {
10             SetText(_T(""));//用户没输入,还是显示预制提示信息
11         }
12         Invalidate();
13     }
14     if( event.Type == UIEVENT_KILLFOCUS && IsEnabled() ) 
15     {
16         if (_tcscmp(GetText(),GetSrcTipValue()) != 0)
17         {
18             SetText(GetText());//同上
19         }
20         else
21         {
22             SetText(_T(""));//同上
23         }
24         Invalidate();
25     }
26 //////////////////////////////

2.在PaintText 做了修改

  

    CString sText = m_sText;

    if(! m_sText.IsEmpty() )//用户输入
    {
        if (m_bPasswordMode)//密码模式
        {
            if (m_sText != m_sSrcTipValue)//用户输入
            {
                int nlen = sText.GetLength();
                sText = "";
                for(int i = 0; i < nlen; i++)
                {
                    sText += '*';
                }
            }
        }
    }
    else if (!m_sSrcTipValue.IsEmpty())//用户没有输入
    {
        sText = m_sSrcTipValue;
        mCurTextColor = m_sTipValueColor;
    }

 Demo程序:

http://files.cnblogs.com/files/chechen/DuilibEdit.rar

原文地址:https://www.cnblogs.com/chechen/p/5341635.html