获取已安装字体列表

7

有没有办法将已安装的字体作为列表(或数组,但我更喜欢列表)获取。

就像一个方法,它会将所有已安装的字体输出到列表中。 到目前为止,我已经创建了这个:

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

有没有更好的方法可以提供?

可能是使用可用字体列表填充ComboBox的重复问题。 - Tomas Kubes
2个回答

24

你需要使用InstalledFontCollection类:

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);
    }
}

0

这是一种更简单的方法(首先创建一个列表框)-

using InstalledFontCollection col = new();
foreach (FontFamily fa in col.Families)
{
    ListBox.Items.Add(fa.Name);
}

别忘记加上!-

using System.Drawing.Text;

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