How can I paint CEdit Control without uncovered ar

2019-08-30 01:38发布

问题:

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;


标签: c++ mfc cedit