CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    1

    How can I can the text and background color of CEdit control ?





    I create a dialog with a CEdit control in it using resource editor. It work fine. But now I want to change the text and backgroung color .i.e. background black and text is white. Can anybody know how to do this ? Thanks in advance.

  2. #2
    Join Date
    May 1999
    Posts
    67

    Re: How can I can the text and background color of CEdit control ?



    Hi,

    the colors of controls in a dialog is controlled by the WM_CTLCOLOR message send to the control. There you can change

    the colors of each control. You must return a brush handle. Here some sample if you use MFC:

    //this member you create using class wizard

    HBRUSH CPassWordDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)

    {

    // default returns brush, but you can use your own

    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here

    if ( pWnd->GetDlgCtrlID( ) == YourControl_ID )

    {

    pDC->SetTextColor(COLOR_TEXT);

    pDC->SetBkColor(COLOR_BACKGND);

    hbr = m_Brush; // your own brush for the background of your control

    }

    // TODO: Return a different brush if the default is not desired

    return hbr;

    }


    Hope this helps

    R.Seibert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured