2011-12-28 25 views
1

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

所以像一个将所有安装的字体列表的方法。 我迄今创造了这个

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

任何想法,或者有人可以提供一个更好的办法? 谢谢。

+6

也许有点前问谷歌搜索? http://msdn.microsoft.com/en-us/library/0yf5t4e8.aspx – ken2k 2011-12-28 15:36:13

+0

这将返回一个数组,我需要一个列表。 – 2011-12-28 15:37:38

+6

然后谷歌另一次:http://stackoverflow.com/questions/1603170/conversion-of-system-array-to-list – ken2k 2011-12-28 15:40:28

回答

17

你想要的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); 
    } 
} 
相关问题