How can I paint CEdit Control without uncovered ar

2019-08-30 01:32发布

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?

Image

标签: c++ mfc cedit
1条回答
Animai°情兽
2楼-- · 2019-08-30 02:22

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;
查看更多
登录 后发表回答