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