Solved

Change color of Edit Box

Posted on 2003-11-07
1
424 Views
Last Modified: 2013-11-20
Hi,

I am working with Dialog Based application. I have an edit box of type CString.
Is there a way where I can change the text color inside that box to any color I want?

PS: I don't want to change the text color for my whole dialog, just for that particualr box.

Thanks
0
Comment
Question by:mfcseeker
1 Comment
 
LVL 5

Accepted Solution

by:
waelothman earned 50 total points
ID: 9705414
try this
class CTestDlg : public CDialog
{
protected:
 CBrush m_redbrush;
};


Then, add these lines in the OnInitDialog function:

BOOL CTestDlg::OnInitDialog()
{
 m_redbrush.CreateSolidBrush(RGB(255,0,0));    
}
Finally do this on the ID_CTLCOLOR handle:

HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
  HBRUSH hbr;

  switch (nCtlColor)
  {
  // process my edit controls by ID.
  case CTLCOLOR_EDIT:

  switch (pWnd->GetDlgCtrlID())
    {    
    case IDC_EDIT1 :         // the id of your controle
     pDC->SetBkColor(RGB(255,0,0));  
      pDC->SetTextColor(RGB(0,254,0));  // change the text color
      hbr = (HBRUSH)  m_redbrush;
      break;  
   default:
      hbr=CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
      break;
    }  
    break;
 default:
    hbr=CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  }

  return hbr; }
wait yor commeny
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now