How to change the background color of a edit box if user modifies its content in MFC. How to change it in ON_EN_CHANGE MSg of a Edit control.
basically your solution is
HBRUSH CEditDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
switch (nCtlColor) {
case CTLCOLOR_EDIT:
case CTLCOLOR_MSGBOX:
// Set color to green on black and return the background
brush.
pDC->SetTextColor(RGB(0, 255, 0));
if(ChangeColor == TRUE)
{
pDC->SetBkColor(RGB(0, 0, 0));
ChangeColor = FALSE;
}
return (HBRUSH)(m_pEditBkBrush->GetSafeHandle());
default:
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
}
Now you want textbox color change on text change then,
::OnEnchange()
{
ChangeColor = TRUE; //Its global flag maintain in any global position may be in your .H file.
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.