Share via


How do I change the font size? How do I change the font?

Question

Thursday, September 14, 2006 3:28 AM

I just created a C++ MFC dialog project. In VB and C#, it is easy to change the font size and to change the font for labels, text boxes, and all the controls. I just set the property in the properties box. Or in a program, I just set the same property.

 

I don't see how to change the font or font size in my project. There are properties to center and to change the text displayed. But I do not see any property called "font".

 

Is there a way to change the font and font size in MFC for individual controls and for forms? I sure don't see anything. There must be a way to change something so basic. How?

All replies (4)

Thursday, September 14, 2006 5:00 AM ✅Answered

For VS 6.0. Go to the resource view and select your dialog. On the title bar of the dialog, right click and choose properties. The Dialog Properties dialog box opens. Click the Font button and now you can select the required font.

In case of VS 2003/2005, when you right click on the dialog title bar, a dialog properties task pane opens, and you can edit the value of the Font Property.

The above method will change the font of all controls. To change the font of a specific control, you can use the function CWnd::SetFont for that particular control, since most of controls are derived from CWnd.

Regards

Simer


Monday, September 18, 2006 5:10 AM ✅Answered

Where as most of the controls provided by Visual Studio can be mapped to a variable (either a control type variable or a Value type variable), a static control cannot be mapped to a variable. Hence the only to way you can locate this in your code is by using the function GetDlgItem(nControlID).

The code snippet shown below, get the CWnd pointer for your control and then you can manipulate the properties programmatically.

CWnd* pWnd = GetDlgItem(IDC_STATIC);

pWnd->SetFont(...);

Regards


Friday, September 15, 2006 2:38 AM

That is a great explanation. I found how to change the fonts right away from your explanation.

However, I am having trouble finding the controls in code. I have an IDC_STATIC1 which I renamed IDC_STATIC_Label. I suppose my rename breaks convention. I thought I would be able to easily find where to make use of CWnd::SetFont. But I don't find anything for IDC_STATIC_Label that looks like a constructor. IDC_STATIC_Label looks like it is only a #define to identify Windows Messages which is also used in some kind of resource file. I don't know much at all about Windows Messages. I was hoping that MFC would take care of the Windows Messages for me. But then, I also don't see the WinMain(), WMain(), or whatever it is, either.

Could I get a pointer on where I can find my static label so I can change its font using SetFont?

 


Tuesday, September 19, 2006 1:37 AM

Excellent! I appreciate your help.