字体向后不兼容

时间:2009-06-16 08:08:41

标签: winforms fonts windows-xp

我正在为我的winforms应用程序使用Segoe UI。

在XP上,此字体不存在,我希望我的应用程序使用Verdana。

实现这一目标的最佳方式是什么。

3 个答案:

答案 0 :(得分:3)

最好使用默认(系统)字体来实现本机外观。所以Vista使用'Sergoe UI'作为默认字体,而XP则使用'Tahoma'(不是'Verdana')。要获取默认对话框字体,请使用SystemFonts类:

protected override void OnLoad(EventArgs e)
{
  base.OnLoad(e);
  Font = SystemFonts.DialogFont;
}

答案 1 :(得分:0)

你想要的是这样的:

Font GetUIFont()
{
    Font testFont = new Font("Segoe UI", 10f);
    if (testFont.Name == "Segoe UI")
        return testFont;
    else
        return new Font("Verdana", 10f);
}

答案 2 :(得分:0)

从JasonH的解决方案开始,包括关于从Form派生的部分。如果您的控件没有自动继承Form的字体,请在表单具有所有控件时调用此代码:

foreach (Control ctl in this.Controls)
{
    ctl.Font = GetUIFont();
}
相关问题