在winforms上使用otf字体是否可行?

5

我尝试在标签、文本框和绘画事件中使用开放式字体,但都无法生效。是否有办法让开放式字体正常工作?


字体 textFont = new Font("Arial Bold", 18F); g.DrawString("12", textFont, solidbrush, 109, 40); 为什么不能像这样使用。 - Sai Kalyan Kumar Akshinthala
我可以,但我只能使用True Type字体。即Myriad Pro无法使用。 - Bildsoe
它的哪个方面不起作用? - Fredrik Mörk
@Frederik - 屏幕上渲染的字体没有改变。它仍然是 Microsoft Sans Serif。而且在尝试创建标签时,对话框告诉我标签只支持 True Type 字体。 - Bildsoe
2个回答

9

在Winforms中不可能实现,因为GDI+仅支持TrueType字体。您需要转向WPF以获得OpenType支持。


5
你可以像在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;
    }  

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接