获取安装的字体作为列表 [英] Obtain installed fonts as a list

查看:138
本文介绍了获取安装的字体作为列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法,我可以获得安装的字体作为列表(或数组,但我更喜欢一个列表)。

所以像一个方法,将所有安装字体列表。
我已经创建了这个

  List< string> fonts = new List< string>(); 
fonts.AddRange()//我不知道要在这些括号里放什么来获取字体。

任何想法,还是可以有人提供更好的方法?
谢谢。

解决方案

您想要 $ b $ b

 使用System.Drawing.Text; 
using(InstalledFontCollection fontsCollection = new InstalledFontCollection())
{
FontFamily [] fontFamilies = fontsCollection.Families;
列表< string> fonts = new List< string>();
foreach(fontFamilies中的FontFamily字体)
{
fonts.Add(font.Source);
}
}


is there any way I can obtain installed fonts as a list (or array, but I prefer a List).

So like a method that will out all installed fonts to a list. I have so far created this

List<string> fonts = new List<string>();
fonts.AddRange() //I don't know what to put in those brackets to obtain fonts.

Any Ideas, or can someone provide a better way? Thank you.

解决方案

You want the InstalledFontCollection class:

using System.Drawing.Text;
using (InstalledFontCollection fontsCollection = new InstalledFontCollection())
{
    FontFamily[] fontFamilies = fontsCollection.Families;
    List<string> fonts = new List<string>();   
    foreach (FontFamily font in fontFamilies)
    {
       fonts.Add(font.Source);
    }
}

这篇关于获取安装的字体作为列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆