获取已安装的所有字体列表
System.Drawing.FontFamily
StringBuilder str = new StringBuilder(2000);
InstalledFontCollection fonts = new InstalledFontCollection();
foreach (FontFamily family in fonts.Families)
{
str.Append(family.Name);
str.AppendLine();
}
ContentTextBlock.Text = str.ToString();

获取区域语言字体列表
System.Windows.Media.FontFamily
StringBuilder str = new StringBuilder(2000);
CultureInfo currentCulture = CultureInfo.CurrentUICulture;
CultureInfo enUsCultureInfo = new CultureInfo("en-US");
foreach (var family in Fonts.SystemFontFamilies)
{
foreach (var keyPair in family.FamilyNames)
{
var specificCulture = keyPair.Key.GetSpecificCulture();
if (specificCulture.Equals(currentCulture) || specificCulture.Equals(enUsCultureInfo))
{
if (keyPair.Key != null && !string.IsNullOrEmpty(keyPair.Value))
{
str.Append(keyPair.Value);
str.AppendLine();
}
}
}
}
ContentTextBlock.Text = str.ToString();

注:有些电脑因系统缺陷或者系统更新冲突,导致System.Windows.Media.Fonts引用失败。所以建议加个异常捕获处理。

以上就是C# 获取系统字体的示例代码的详细内容,更多关于c# 获取字体的资料请关注其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)