Font backward incompatibility

Go To StackoverFlow.com

3

I am using Segoe UI for my winforms application.

On XP, this font doesn't exist and I would like to have my app use Verdana instead.

What's the best way of achieving that.

2009-06-16 08:08
by WOPR


3

It is always better to use default (system) font to achieve native look. So Vista uses 'Sergoe UI' as default font, and XP uses 'Tahoma' for this (not 'Verdana'). To get default dialog font use SystemFonts class:

protected override void OnLoad(EventArgs e)
{
  base.OnLoad(e);
  Font = SystemFonts.DialogFont;
}
2009-06-21 10:17
by arbiter


0

What you want is something like this:

Font GetUIFont()
{
    Font testFont = new Font("Segoe UI", 10f);
    if (testFont.Name == "Segoe UI")
        return testFont;
    else
        return new Font("Verdana", 10f);
}
2009-06-16 08:16
by jasonh
...but how do you do that automatically, for every form and control in your application? How do you make sure that the layout is still correct? etc. etc - Roger Lipscombe 2009-06-16 08:31
What you could do is derive from Form and then use your derived class. In the constructor for your derived form you could call the GetUIFont method to set the Form's font and then that would make it automatic. As far as layout, I've always seen my forms adjust automatically when I change the font size. You'll probably have to play around with that one and if you have problems, you can always ask for help here. ; - jasonh 2009-06-16 16:52


0

Start with JasonH's solution, including the part about deriving from Form. If you have problems with controls that don't inherit the Form's font automatically, call this code when your form has all of its controls:

foreach (Control ctl in this.Controls)
{
    ctl.Font = GetUIFont();
}
2009-06-18 18:07
by stone