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.