How can I paint CEdit Control without uncovered area?

无人久伴 提交于 2019-12-13 21:50:22

问题


I have CDialg and CEdit Control on dialog. So, to paint CEdit control without sub-classing CEdit Class, I used CDialog::OnCtlColor like this.

if( nCtlColor == CTLCOLOR_EDIT )
{
    pDC->SetBkColor(RGB(200, 255, 200));
}

But as you can see, that it omits some margin area of edit control.

How can I paint it whole window Rect of CEdit?


回答1:


You also need to return a brush with the correct colour, so create a brush in the dialog constructor

#define EDITCOLOR RGB(200, 255, 200)
m_brEdit.CreateSolidBrush(EDITCOLOR);

and in the OnCtlColor() function,

HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_EDIT)
{   pDC->SetBkColor(EDITCOLOR);
    hbr = m_brEdit;
}
return hbr;


来源:https://stackoverflow.com/questions/26685432/how-can-i-paint-cedit-control-without-uncovered-area

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!