views:

2340

answers:

5

Hello,

Everytime I create new form in my application, it uses "Microsoft Sans Serif, 8.25pt" font by default. I'm not changing it, because I know that in this case my form will pick up whatever default font in system is. However, when I run my application, the font is still anything but Segoe UI.

Why this happens? How do I make sure that my application looks like normal Windows application?

Thanks.

+3  A: 

Yes, it uses the font returned by GetStockObject(DEFAULT_GUI_FONT). Which is MS Sans Serif. An old font, long gone from most machines. The font mapper translate it to, no surprise, Microsoft Sans Serif.

There is no documented procedure I know of to change that default font, the SDK docs mention MS Sans Serif explicitly. If you want Segoe, you'll have to ask for it. Which isn't that safe to do, there are still a lot of XP machines out there without Office 2007. The font mapper will translate it on a machine that doesn't have Segoe available. Not sure what pops out, I don't have such a machine left anymore.

Hans Passant
That's really sad. :(
+5  A: 

Check out this blog entry talking about the default font in Forms which leads to the problem you are experiencing and this Connect Bug with Microsoft's response. In short it just seems that Forms does not get the (correct) default windows font (which you have changed).

Robert Wagner
+3  A: 

You can add before InitializeComponent() in the Form constructor(s):

this.Font = SystemFonts.MessageBoxFont;

This appear to work with Windows XP and Windows Vista.

CS
Yes, this is the work-around I usually use.
Lucas
+1  A: 

Setting the form's Font property to SystemFonts.DialogFont doesn't work if you have group boxes with associated controls. The controls inside the group box are not affected by the form's Font property. I "solved" this by setting the Font property to SystemFonts.DialogFont for each and every group box.

josuegomes