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

    Change CStatic Background Color?

    Anybody know a quick and simple way to change the background color of a CStatic control? If you do please include a snip-it of code in reply.
    Last edited by nouser; April 18th, 2009 at 10:03 PM.

  2. #2
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Change CStatic Background Color?

    This topic has been covered many, many times.

    Override the static's parent's OnCtlColor() like this:

    ---
    HBRUSH CSomeWndOrDlg::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor)
    {
    HBRUSH hBrBkgnd = CBaseClass::OnCtlColor(pDC, pWnd, nCtlColor);

    if (nCtlColor == CTLCOLOR_STATIC)
    {
    hBrBkgnd = get_your_HBRUSH_for_back_colour_here ;
    pDC->SetBkColor(same_colour_as_above_but_as_COLORREF);
    }

    return hBrBkgnd ;
    }


    ---

    OK?



    --
    Jason Teagle
    [email protected]

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