Take static text for example to share how to modify text font, size, color, background and other parameters. Other text, controls, etc. can be modified by reference.
1. Modify font, size
This is simple, first declare a member variable of type CFont in the Dlg class:
Then add the following two lines of code to the class's initialization function, OnInitDialog ():
1 // set the static text font size 2 M_editfont.createpointfont (_t (" song body ")); 3 M_static.setfont (&m_editfont);
2. Change edit box text color, background color
Right-click the dialog box, class-guided message, double-click Add wm_ctlcolor, you can see the 3 function OnCtlColor in the Dlg class.
1Hbrush Ctimerdlg::onctlcolor (cdc* PDC, cwnd*pWnd, UINT nCtlColor)2 3 {4 5Hbrush HBR =Cdialogex::onctlcolor (PDC, PWnd, nCtlColor);6 7 8 9 //TODO: Change any of the properties of the DC hereTen One if(Pwnd->getdlgctrlid () = = Idc_display)//Idc_display for the selected text box ID A - { - thePdc->settextcolor (RGB (255,0,0));//Set Font Color - -Pdc->setbkcolor (RGB (0,255,0));//Set Background color - + //Pdc->setbkmode (TRANSPARENT);//Set Background Transparency - + } A at //TODO: If the default is not the desired brush, another brush is returned - - returnHBR; - -}
In addition to setting the color and background of a static control, the OnCtlColor function applies to several types:
Ctlcolor_btn Button controls
Ctlcolor_dlg dialog box
Ctlcolor_edit edit Box
Ctlcolor_listbox List control
Ctlcolor_msgbox Message Control
Ctlcolor_scrollbar scroll bar control
Ctlcolor_static Static controls
In addition to setting the property with the ID specified above, you can also specify a control type to set the property .
1Hbrush Ctimerdlg::onctlcolor (cdc* PDC, cwnd*pWnd, UINT nCtlColor)2 3 {4 5Hbrush HBR =Cdialogex::onctlcolor (PDC, PWnd, nCtlColor);6 7 8 9 //TODO: Change any of the properties of the DC hereTen One if(nCtlColor = =ctlcolor_static) A - { - thePdc->settextcolor (RGB (0,255,0));//Set Font Color - -Pdc->setbkcolor (RGB (255,0,0));//Set Background color - + } - + //TODO: If the default is not the desired brush, another brush is returned A at returnHBR; - -}
End:)
MFC series MFC quick Set control text font, size, color, background