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

    Static Text Color

    How do I change the background color of a Static Text item on a dialog?


  2. #2
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    Re: Static Text Color

    Have a look in the static controls section of this site.
    There is an article called 'Extended use of CStatic Class'
    or something like that. It can do lots of things to static text !



  3. #3
    Join Date
    Apr 1999
    Posts
    76

    Re: Static Text Color

    The control background is painted with the brush returned from OnCtlColor.
    You can accomplish what you are looking for like this:

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

    // handle only STATIC controls
    if( nCtlColor == CTLCOLOR_STATIC )
    {
    short ID = pWnd->GetDlgCtrlID(); // get STATIC's control ID
    if( ID == IDC_STATIC11 ) // if the right control, change color
    {
    pDC->SetTextColor(RGB(255,255,255));
    pDC->SetBkMode(TRANSPARENT);
    hbr = (HBRUSH)::GetStockObject(BLACK_BRUSH);
    }
    }

    return hbr;
    }


  4. #4
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    Re: Static Text Color

    That method would work for one control and would be somewhat
    cumbersome to use for more than one. The class I mentioned
    can control the foreground and background color and the font
    type and style also. I believe that this is easier to use then the
    method you posted although it does require one to download the
    class. To use the CLabel class one declares a variable of type
    CLabel and then calls its control methods such as :

    m_static1.SetBkColor(crBkgnd); // sets background colour
    m_static1.SetTextColor(crText); // sets foreground colour

    Of course, these are my opinions. Your mileage may vary.

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