How to change the text color in a disabled edit box using MFC?

Posted by anand.arumug on Stack Overflow See other posts from Stack Overflow or by anand.arumug
Published on 2010-06-18T15:48:39Z Indexed on 2010/06/18 15:53 UTC
Read the original article Hit count: 275

Filed under:
|
|
|

Hello all,

I have a dialog in which the edit box is disabled but the text should be displayed in red instead of the default grey. I tried the following:

void CMyEdit::OnEnable(BOOL bEnable)
{
  CEdit::OnEnable(bEnable);

  if (bEnable)
  {
    m_BackGroundColor = kRGBWhite;
  }
  else
  {
    m_BackGroundColor = kRGBDefaultGray;
  }

  m_TextColor = kRGBRed;
  m_BackgroundBrush.DeleteObject();
  m_BackgroundBrush.CreateSolidBrush(m_BackGroundColor);

  Invalidate();
}

But its still displaying the text in grey only. But if I remove the base class call CEdit::OnEnable(bEnable); then new text color takes effect. Can anyone explain whats wrong in the code?

Thanks for your time.

cheers...

© Stack Overflow or respective owner

Related posts about mfc

Related posts about win32