C# 获取系统字体的示例代码
程序员文章站
2022-04-10 16:51:02
获取已安装的所有字体列表system.drawing.fontfamilystringbuilder str = new stringbuilder(2000); installedfontcoll...
获取已安装的所有字体列表
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# 获取字体的资料请关注其它相关文章!
上一篇: 腐竹怎么泡最快?腐竹的价格是怎么样的?
下一篇: 井水的水源来自哪里?井水发黄怎么办?