Solved

Change color of Edit Box

Posted on 2003-11-07
1
427 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Whole sheet autoscrub still needed 19 48
post4 challenge 28 92
NotAlone Challenge 20 79
How to convert MFC::CString to UTF8 wchar_t* 10 137
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

930 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

18 Experts available now in Live!

Get 1:1 Help Now