Getting Windows installed fonts using .NET

Waqas Anwar
21 March 2008
5349 Views

.NET Framework 2.0 namespaces System.Drawing and System.Drawing.Text contains many useful classes related to Drawing manipulation. These classes deals with fonts, fonts families, colors, images and bitmaps and can be used to add drawing related features in your .NET applications. One of the common task developers needs to perform in day to day .NET applications is to get the list of installed fonts in Windows operating system.

Windows Installed Fonts

Following tutorial demonstrates how you can achieve this by using .NET built in classes.

VB.NET

Dim fontsCollection As New InstalledFontCollection()
Dim fontFamilies As FontFamily() = fontsCollection.Families
Dim count As Integer = fontFamilies.Length

Me.Text = "Number of fonts:" + count

For Each font As FontFamily In fontFamilies
   listBox1.Items.Add(font.Name)
Next


C#

InstalledFontCollection fontsCollection = new InstalledFontCollection();
FontFamily[] fontFamilies = fontsCollection.Families;
int count = fontFamilies.Length;

this.Text = "Number of fonts:" + count;

foreach (FontFamily font in fontFamilies)
{
   listBox1.Items.Add(font.Name);
}