Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default font for Windows Forms application

Every time that I create a new form in my application, it uses the "Microsoft Sans Serif, 8.25pt" font by default. I'm not changing it because I know that in this case my form should pick up whatever the default font is for the system. However, when I run my application, the font that is used is still anything but Segoe UI (my default system font in my Windows Vista OS).

Why does this happen? How do I make sure that my application looks like a normal Windows application?

like image 461
wasker Avatar asked Nov 18 '08 02:11

wasker


People also ask

What is default font in C#?

If the above fonts are not installed, the default font is Tahoma, 8 point.

What font does Windows 10 use by default?

Even though the default fonts provided by Microsoft—Segoe UI for Windows 10, and Segoe UI variable for Windows 11—looks pretty neat on the screen, you don't have to settle if you have grown bored with them; especially when you can easily alter them with the Windows Registry.

What is the default WPF font?

In WPF, the default font family for text displayed on controls (like Label and Button) is Segoe UI, with a default size of 12.0 device-independent units. Because a device-independent unit is 1/96 inch, a FontSize value of 12 represents characters whose capitals are 1/8″ high.


2 Answers

The accepted answer doesn't really answer the question; it just explains why this behavior is occurring.

Some of the other answers propose solid workarounds, but I've found that the best solution really is to create a base form that all of the forms in your application inherit from and set this base form's Font property to SystemFonts.MessageBoxFont in the constructor. This not only ensures that your application picks up the correct font at run-time, based on the user's environment (heading off the potential problem posed by Hans Passant—an XP without Office 2007 will resort to Microsoft Sans Serif in the absence of Segoe UI), but also gives you design-time support for your current Windows font. Using the correct font at design time solves the problem Josuegomes points out, because any container control that is created on the form will pick up the font used by the form at design-time.

Besides the above advantages, this frees you from having to remember to modify the constructor for each form that you create and ensures consistency across all of the forms in your application, as well as giving you a place to put other common functionality. I use this in a couple of different ways such as p/invoking, etc. to fix bugs in the WinForms implementation.

The only problem that remains with this approach is if you want to set a font style for a particular control, such as bold. The best place to do this is still in that form's constructor, starting with the form's font as a base and modifying the style from it:

myControl.Font = New Font(Me.Font, FontStyle.Bold) 
like image 158
Cody Gray Avatar answered Sep 24 '22 23:09

Cody Gray


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

this.Font = SystemFonts.MessageBoxFont; 

This appear to work with Windows XP and Windows Vista.

like image 37
CS. Avatar answered Sep 21 '22 23:09

CS.