Change font and background color in MFC

Source: Internet
Author: User

1. Change the font size and style of the control.
Cfont m_lfont;
Void XX: changelistfontsize (void)
{
M_lfont.createfont (
25, // nheight
0, // nwidth
0, // nescapement
0, // norientation
// Fw_normal, // nweight
Fw_medium,
// Fw_semibold,
False, // bitalic
False, // bunderline
0, // cstrikeout
// Ansi_charset,
Default_charset, // ncharset
Out_default_precis, // noutprecision
Clip_default_precis, // nclipprecision
Default_quality, // nquality
Default_pitch | ff_swiss, // npitchandfamily
_ T (" "));
Getdlgitem (idc_list_music)-> setfont (& m_lfont );
Getdlgitem (idc_static_music)-> setfont (& m_lfont );
}
2. Change the font size and style of the header in listctrl.
Cfont m_hfont;
Void XX: changepricelistheadfontsize (void)
{
M_hfont.createfont (
18, // nheight
0, // nwidth
0, // nescapement
0, // norientation
Fw_normal, // nweight
// Fw_medium,
// Fw_semibold,
False, // bitalic
False, // bunderline
0, // cstrikeout
// Ansi_charset,
Default_charset, // ncharset
Out_default_precis, // noutprecision
Clip_default_precis, // nclipprecision
Default_quality, // nquality
Default_pitch | ff_swiss, // npitchandfamily
_ T (" "));
Cheaderctrl * pheaderctrl = m_pricelist.getheaderctrl ();
Pheaderctrl-> setfont (& m_hfont );
}
3. Change the background color of the form, static box, edit box, And listctrl.
Cbrush m_brush;
In initialization:
Getparentframe ()-> recalclayout ();
M_brush.createsolidbrush (RGB (140,20, 15 ));
Override onctlcolor
Hbrush XX: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor)
{
Hbrush HBr = cformview: onctlcolor (PDC, pwnd, nctlcolor );

// Todo: change any attributes of the DC here
If (nctlcolor = ctlcolor_edit)
{
If (pwnd = getdlgitem (idc_edt_text) | pwnd = getdlgitem (idc_edt_price ))
{
PDC-> settextcolor (RGB (255,255,255 ));
PDC-> setbkmode (transparent); // set the background to transparent
}
}
If (nctlcolor = ctlcolor_static)
{
PDC-> settextcolor (RGB (255,255,255 ));
Hbrush hnullbr = (hbrush): getstockobject (null_brush );
PDC-> setbkmode (transparent); // set the background to transparent
Return hnullbr;
}
// Todo: return a different brush if the default is not desired
Return m_brush;
}

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.