About Classes used -
- An object of InstalledFontCollection class looks for fonts installed in
Windows before the object is created.
- This FontFamily class encapsulates a set of fonts that make up a font
family.
A font family is a group of fonts that have the same typeface but different
styles.
Here I implemented the Code for retrieving the fonts installed on the System.
The Code:
1. Put the following code at OnClick Event of the Combobox control to
fetch the fonts into it.
private void cbSelectFont_Click(object sender, EventArgs e)
{
//retrieves fonts collection on the system
using (InstalledFontCollection ff
= new InstalledFontCollection())
{
foreach (FontFamily item in ff.Families) //retrieves
font families
{
cbSelectFont.Items.Add(item.Name.ToString());
}
}
}
Listing 1
2. (Optional) Now you can apply these fonts for other control(s) also.
(Here I used it for a Label Control)
3. Now execute the Application and see the result (Figure 1).
Intended Result:
Figure 1
Summary:
In this piece of writing, we have seen how to retrieve the installed fonts of
the system using C# Language.