问题
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.
Can someone provide a better way?
回答1:
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);
}
}
来源:https://stackoverflow.com/questions/8657821/obtain-installed-fonts-as-a-list