使用可用字体列表填充ComboBox

Moo*_*oon 38 c# fonts windows-xp winforms

如何在组合框中填入系统中所有可用字体的列表?

Zac*_*son 63

您可以使用System.Drawing.FontFamily.Families获取可用字体.

List<string> fonts = new List<string>();

foreach (FontFamily font in System.Drawing.FontFamily.Families)
{
    fonts.Add(font.Name);
}

// add the fonts to your ComboBox here
Run Code Online (Sandbox Code Playgroud)


Pau*_*aul 8

不知道为什么我们需要在foreach这里.

IList<string> fontNames = FontFamily.Families.Select(f => f.Name).ToList();
Run Code Online (Sandbox Code Playgroud)

  • `IList&lt;string&gt; fontNames = FontFamily.Families.Select(f =&gt; f.Name).ToList();` ComboBox 不接受 `IEnumerable`。 (2认同)