【问题标题】:Is it possible to use otf fonts on winforms?是否可以在 winforms 上使用 otf 字体?
【发布时间】:2011-08-04 14:51:49
【问题描述】:

我尝试在标签、文本框和绘制事件中使用 Open Type Fonts。但它不起作用。有什么方法可以让 Open Type Font 工作吗?

【问题讨论】:

  • 字体 textFont = new Font("Arial Bold", 18F); g.DrawString("12", textFont, solidbrush, 109, 40);为什么不能这样使用。
  • 我可以,但我只适用于 True Type 字体。 IE。 Myriad Pro 无法使用。
  • 在什么情况下不起作用?
  • @Frederik - 屏幕上呈现的字体没有改变。它仍然是 Microsoft 无衬线字体。当尝试创建标签时,一个对话框告诉我标签只支持 True Type 字体。

标签: c# winforms opentype


【解决方案1】:

这在 Winforms 中是不可能的,GDI+ 只支持 TrueType 字体。您必须迁移到 WPF 才能获得 OpenType 支持。

【讨论】:

    【解决方案2】:

    您可以像在 WPF 中那样使用 System.Windows.Media 命名空间,这里有一个示例:

    public static string GetFontList(String ElementSeparator)
        {
            string r = "";
    
            // WPF incl Adobe and OpenType
            foreach (System.Windows.Media.FontFamily fontFam in System.Windows.Media.Fonts.SystemFontFamilies)
            {
                r += fontFam.Source;
                r += ElementSeparator;
            }
    
            // True type, incl Type face names e.g. Arial Rounded MT Bold
            foreach (System.Drawing.FontFamily f in System.Drawing.FontFamily.Families)
            { 
                if(!r.Contains(f.Name))
                {
                r += f.Name;
                r += ElementSeparator;
                }
            }            
    
            return r;
        }  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-14
      • 1970-01-01
      • 2011-03-15
      • 2014-04-27
      • 2014-03-17
      • 2016-03-22
      • 2017-11-24
      • 1970-01-01
      相关资源
      最近更新 更多