如何:枚举系统字体

更新:2007 年 11 月

示例

下面的示例演示如何枚举系统字体集合中的字体。将 SystemFontFamilies 中的每一个 FontFamily 字体系列的名称作为一项添加到组合框中。

public void FillFontComboBox(ComboBox comboBoxFonts)
{
    // Enumerate the current set of system fonts,
    // and fill the combo box with the names of the fonts.
    foreach (FontFamily fontFamily in Fonts.SystemFontFamilies)
    {
        // FontFamily.Source contains the font family name.
        comboBoxFonts.Items.Add(fontFamily.Source);
    }

    comboBoxFonts.SelectedIndex = 0;
}

如果同一字体系列的多个版本位于同一目录,则 Windows Presentation Foundation (WPF) 字体枚举返回字体的最新版本。如果版本信息不提供解析,则返回具有最新时间戳的字体。如果时间戳信息相等,则返回字母排序为第一的字体文件。