MFC control font styles and color settings

Source: Internet
Author: User

Because the default font size is small, and sometimes for the sake of aesthetics,the font style change of the MFC control sometimes becomes more important. This modification is not very intuitive and needs to be done by code, as follows:

CFont *m_pfont;//Create new Font m_pfont = new Cfont;m_pfont->createfont (32,//font height 0,//font    width    0,//font tilt angle    0,//font inclination Bevel        Fw_extralight,         //font weight    false,//font is italic    false,//font is underlined    0,//font has strikethrough    ansi_charset,         //Character set    used by font Out_default_precis,                      //Specifies how to select the appropriate font    CLIP_DEFAULT_PRECIS,                     //To determine the clipping accuracy    default_quality,                 // How to match the selected font    Default_pitch | Ff_swiss,                         //spacing flags and attribute flags    _t ("italics"));         The name of the font//Label control M_editcontrol.setfont (M_pfont, false);//The edit box is associated with the Set Font//button control mybutton. SetFont (M_pfont, false);//For keystrokes, MyButton is the CButton object//list control. SetFont (M_pfont, false);//list for CListCtrl object List.insertcolumn (0, _t ("School Number"), Lvcfmt_left, "a"); list. InsertColumn (1, _t ("name"), Lvcfmt_left, 110);
to change the font color of a control is a bit more complicated, and the following points need to be made

1. Defining Brush objects

CBrush m_brush;//Paint Brush Tool
   2. Initialize the Brush object
M_brush.createsolidbrush (GetSysColor (Color_3dface));//Initialize Brush, return dialog box background color with GetSysColor
3. Add the WM_CTLCOLOR Message of the dialog box accordingly

4. Add the following code to the message response function in the dialog box

if (nCtlColor = = ctlcolor_static)//ctlcolor_static is a Label control {if (pwnd->getdlgctrlid () = = Idc_static_font)//specific one of the labels, Idc_static_font is a Label control Id{pdc->setbkmode (Bkmode_last);//Transparent Pdc->settextcolor (RGB (255, 0, 0));//Text color  //pdc- >setbkcolor (RGB (251, 247, 200));//Background color return (hbrush) M_brush.getsafehandle ();}}
after the above operation, you can get the following effect:

  Unmodified image modified after original

MFC control font styles and color settings

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.