.NET Framework 1.0 and above
By Microsoft's design guidelines you should be using system defined font for displaying user interface elements in your program. Of course, Microsoft found it very helpful to ignore that and assign Microsoft Sans Serif at 8.25 points as default font for all new .NET applications. Since both XP and Vista brought us new font (Tahoma at 8.25 points and Segoe UI at 9 points, respectively) most of .NET applications are just looking slightly out of place.
Solution is quite simple - you should only manually assign new font to form and all elements will pick up that setting (if you left them at default). Only problem is retrieving a font to use.
Microsoft states that we should use GetThemeFont API to get this information. Problem is that this function does not exist in managed world and you don't always have option to make P/Invoke calls (i.e. because of security settings) and portability also comes into question (Windows older than XP and mono).
One would think that SystemFonts.DefaultFont would return what we need but for some reason known only to guy who made that function it returns Microsoft Sans Serif in almost all cases. Why does it ignore real windows default font is unknown to me. Some reflecting is probably needed but I tend to be on lazy side when there is no actual possibility to change anything.
Good choice is strangely SystemFonts.MessageBoxFont since this return proper font on all platforms I have used it. It is not official source for that information but should be good enough if you really want (or need) to stay in managed world.
If one wants to see example of it, I am happy to provide.
2 thoughts to “Default System Font”
Yes, thats the way I’m trying to resolve this problem. I even have tested with different DPI (96 and 120), the form expands, and all its contents too, all is fine, under XP we have Tahoma, under 7 – Segoe, as expected.
But how did you got rid of “virtual member call in constructor” warning?
You should not see that warning. Assuming that you have just
this.Font = SystemFonts.MessageBoxafter
InitializeControls, no warnings should be generated.