Find All Installed Fonts

Problem

You want to retrieve a list of all the fonts on the current computer.

Solution

Create a new instance of the System.Drawing.Text.InstalledFontCollection class, which contains a collection of FontFamily objects representing all the installed fonts.

Discussion

The InstalledFontCollection class allows you to retrieve information about currently installed fonts. The following code uses this technique to fill a list box named lstFonts with a list of valid font names:

Dim FontFamilies As New System.Drawing.Text.InstalledFontCollection()

Dim Family As FontFamily
For Each Family In FontFamilies.Families
    lstFonts.Items.Add(Family.Name)
Next

When an entry is chosen in the list box, the font of a label control is updated:

Private ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.