CEdit's Text Color when Disabled
-
Hi, Does anyone know what is the way to change a CEdit's text color when the control is disabled? I already implemented the reflected OnCtlColor, and it successfully changes the color when the control is enabled, but when disabled, the color becomes gray... Thank you in advance. "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
-
Hi, Does anyone know what is the way to change a CEdit's text color when the control is disabled? I already implemented the reflected OnCtlColor, and it successfully changes the color when the control is enabled, but when disabled, the color becomes gray... Thank you in advance. "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
Vladimir Georgiev wrote: ...but when disabled, the color becomes gray... This is normal (and expected) behavior. If you changed it to some other color, would the user know that the control was disabled, or would they try to interact with it and become frustrated when they couldn't?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
Hi, Does anyone know what is the way to change a CEdit's text color when the control is disabled? I already implemented the reflected OnCtlColor, and it successfully changes the color when the control is enabled, but when disabled, the color becomes gray... Thank you in advance. "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
I found a way to change the text color of a disabled CEdit. 1- You must derive a class from CEdit 2- Overwrite WindowProc and do the following:
LRESULT CMyEditBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_PAINT)
{
DWORD dwStyle = GetStyle();
if (dwStyle & WS_DISABLED)
{
EnableWindow(TRUE); //Trick paint by temporarily enabling CEdit
SetReadOnly(TRUE); //Temporarily making CEdit read onlyLRESULT res = CEdit::WindowProc(message, wParam, lParam); SetRedraw(FALSE); if ((dwStyle&ES\_READONLY) == 0) SetReadOnly(FALSE); //Restore READ ONLY style EnableWindow(FALSE); //Restore DISABLED style SetRedraw(TRUE); CRect rcClient; GetWindowRect(rcClient); ScreenToClient(rcClient); ValidateRect(rcClient); return res; }
}
return CEdit::WindowProc(message, wParam, lParam);
}3- Overwrite CtlColor and change color when control is in read-only state (of course you can use a member variable instead of the read-only style to set disabled text color)
HBRUSH CMyEditBox::CtlColor(CDC* pDC, UINT nCtlColor)
{
if (GetStyle() & ES_READONLY)
{
pDC->SetBkColor(GetSysColor(COLOR_3DFACE));
pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
return GetSysColorBrush(COLOR_3DFACE);
}return NULL;
}