Solved

Change color of Edit Box

Posted on 2003-11-07
1
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 103
sameEnds challenge 3 195
difference between String.subString() and String.subSequence() 6 288
noX challenge 17 144
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

734 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