现在,我将通过以下代码获得字体名称:
PrivateFontCollection fontCollection = new PrivateFontCollection();
fontCollection.AddFontFile("path_to_my_Thai_font");
return fontCollection.Families[0].Name;在英语Win7系统中,我得到了“DFPHeiMedium”,而在中国的Win7系统中,我得到了"華康中黑體(P)-UN“。因此,字体名称在不同的系统语言中有所不同。
我的问题是,如何编写我的代码,以确保我可以始终得到"DFPHeiMedium-UN“,而不管系统语言如何?
谢谢。
顺便说一下,我试过CurrentCulture。我把这一行放在上面的代码前面。还是不工作。Thread.CurrentThread.CurrentCulture =新CultureInfo("en-us");
发布于 2016-12-09 07:45:43
您可以使用接受语言标识符的GetName函数,或者对中性语言使用0:
PrivateFontCollection fontCollection = new PrivateFontCollection();
fontCollection.AddFontFile("path_to_my_Thai_font");
return fontCollection.Families[0].GetName(0);至于为什么您的文化更改不起作用,我们可以看看 in the reference source的实现。
public String Name
{
get
{
return GetName(CurrentLanguage);
}
}如果我们检查CurrentLanguage,我们可以看到它使用的是System.Globalization.CultureInfo.CurrentUICulture.LCID,即当前的UI区域性,而不是CurrentCulture。
https://stackoverflow.com/questions/41053962
复制相似问题