How to: Enumerate System Fonts
Example
The following example shows how to enumerate the fonts in the system font collection. The font family name of each FontFamily within SystemFontFamilies is added as an item to a combo box.
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
If multiple versions of the same font family reside in the same directory, the Windows Presentation Foundation (WPF) font enumeration returns the most recent version of the font. If the version information does not provide resolution, the font with latest timestamp is returned. If the timestamp information is equivalent, the font file that is first in alphabetical order is returned.
.NET Desktop feedback
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for