示例:
以下示例演示如何枚举系统字体集合中的字体。 FontFamily 内的每个 SystemFontFamilies 的字体系列名称会作为项添加到组合框。
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;
}
Public Sub FillFontComboBox(ByVal comboBoxFonts As ComboBox)
' Enumerate the current set of system fonts,
' and fill the combo box with the names of the fonts.
For Each fontFamily As FontFamily In Fonts.SystemFontFamilies
' FontFamily.Source contains the font family name.
comboBoxFonts.Items.Add(fontFamily.Source)
Next fontFamily
comboBoxFonts.SelectedIndex = 0
End Sub
如果同一字体系列的多个版本位于同一目录中,Windows Presentation Foundation (WPF) 字体枚举将返回最新版本的字体。 如果版本信息不提供分辨率,则返回具有最新时间戳的字体。 如果时间戳信息等效,则返回第一个按字母顺序排列的字体文件。