MFC Control Background Color

Source: Internet
Author: User

As needed, the background color of the GroupBox control and the text control static is set to match.

Set GroupBox background color in Onctrlcolor:

if (Pwnd->getdlgctrlid () ==idc_g) {//groupbox background color
CRect RC;
GetDlgItem (Idc_g)->getclientrect (&RC);
Pdc->fillsolidrect (Rc,rgb (70,219,182));
}

if (Pwnd->getdlgctrlid () ==idc_static1) {//static background color
Pdc->setbkcolor (RGB (70,219,182));
}

Set the effect after:

There is a white background does not meet the requirements:

Need to add this sentence: hbr= (hbrush) CreateSolidBrush (RGB (70,219,182));

if (Pwnd->getdlgctrlid () ==idc_static1) {//static background color
Hbr= (Hbrush) CreateSolidBrush (RGB (70,219,182));
Pdc->setbkcolor (RGB (70,219,182));
}

The effect is as follows:

/* Set Control background transparent */
Hbrush Ctooldlg::onctlcolor (cdc* PDC, cwnd* pwnd, UINT nCtlColor)
{
Hbrush HBR = Cdialogex::onctlcolor (PDC, pwnd, nCtlColor);

if (nCtlColor = = ctlcolor_static)
{
Pdc->setbkmode (transparent);/Set Background transparent
Pdc->settextcolor (RGB (255,255,0));//Set Font to Yellow
Return (Hbrush):: Getstockobject (Null_brush);
}

TODO: If the default is not the desired brush, return another brush
return HBR;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.