O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required