How do I change the font of controls in the EDIT Control dialog box?

Source: Internet
Author: User

1. Define CFont m_Font in the public class;

2. OnInitDialog () definition at initialization:

M_Font.CreatePointFont (150, _ T (" 文 "), NULL );

M_ControlEdit.SetFont (& m_Font, FALSE); // m_ControlEdit is the edit control variable to change the font.



Reprinted:

[Question]

Do you feel that the font of the Edit, Static... control is too monotonous and there is nothing new? The following content is for you.

Answer.

[Solution]

Simple Steps: in Windows, each form has its own font. To change its font, you must first

CFont: CreateFont: Create a font, and then use CWnd: SetFont to select the font and assign it to the control. However, many

The number of CreateFont parameters may be prohibitive. I will introduce the parameters below.

Function prototype:

BOOL CreateFont (int nHeight, int nWidth, int nEscapement, int

NOrientation, int nWeight, BYTE bItalic, BYTE bUnderline, BYTE cStrikeOut,

BYTE nCharSet, BYTE nOutPrecision, BYTE nClipPrecision, BYTE nQuality, BYTE

NPitchAndFamily, LPCTSTR lpszFacename );

Parameter description:

NHeight: font height.> 0: font height; = 0: The font is empty and straight. <0: The value is absolute.

The value is the height.

NWidth: font width.

NEscapement: the skew of text lines.

NOrientation: the skew of the character baseline.

NWeight: font width:

. FW_DONTCARE

. FW_THIN

. FW_EXTRALIGHT

.....

BItalic: whether the font is Italic

BUnderline: whether the font is underlined

CStrikeOut: indicates whether the font contains strikethrough.

NCharSet: font Character Set

. ANSI_CHARSET

. DEFAULT_CHARSET

. SYMBOL_CHARSET

......

NOutPrecision: output precision of Characters

NClipPrecision: Specifies the character cropping precision.

NQuality: character output quality

NPitchAndFamily: Character spacing and font family (low-level spacing and High-Level Family)

LpszFacename: font name

[Program Implementation]

Suppose you already have a dialog box project named My. There is an Edit control with ID = IDC_EDIT1.

Class CMyDlg: public CDialog

{

Public:

CFont m_Font;

........

};

BOOL CTMyDlg: OnInitDialog ()

{

CDialog: OnInitDialog ();

// TODO: Add extra initialization here

// CFont m_Font;

M_Font.CreateFont (-

100, 0, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRE

CIS, DEFAULT_QUALITY, FF_SWISS, "Arial ");

CEdit * m_Edit = (CEdit *) GetDlgItem (IDC_EDIT1 );

M_Edit-> SetFont (& m_Font, FALSE );

Return TRUE; // return TRUE unless you set the focus to a control

}

Note: In OnInitDialog (), remove the // CFont m_Font; "//" before, and remove the CFont in the class declaration.

M_Font; what is the result of removing it? Try it by yourself.




This article comes from the blog "beyond its reach", please be sure to keep this source http://b217dgy.blog.51cto.com/5704306/1303095

Related Article

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.