Files
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

2.2 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Enumerate Installed Fonts 03/30/2017
csharp
vb
fonts [Windows Forms], enumerating installed
examples [Windows Forms], fonts
26d74ef5-0f39-4eeb-8d20-00e66e014abe

How to: Enumerate Installed Fonts

The xref:System.Drawing.Text.InstalledFontCollection class inherits from the xref:System.Drawing.Text.FontCollection abstract base class. You can use an xref:System.Drawing.Text.InstalledFontCollection object to enumerate the fonts installed on the computer. The xref:System.Drawing.Text.FontCollection.Families%2A property of an xref:System.Drawing.Text.InstalledFontCollection object is an array of xref:System.Drawing.FontFamily objects.

Example

The following example lists the names of all the font families installed on the computer. The code retrieves the xref:System.Drawing.FontFamily.Name%2A property of each xref:System.Drawing.FontFamily object in the array returned by the xref:System.Drawing.Text.FontCollection.Families%2A property. As the family names are retrieved, they are concatenated to form a comma-separated list. Then the xref:System.Drawing.Graphics.DrawString%2A method of the xref:System.Drawing.Graphics class draws the comma-separated list in a rectangle.

If you run the example code, the output will be similar to that shown in the following illustration:

Screenshot that shows the installed font families.

[!code-csharpSystem.Drawing.FontsAndText#11] [!code-vbSystem.Drawing.FontsAndText#11]

Compiling the Code

The preceding example is designed for use with Windows Forms, and it requires xref:System.Windows.Forms.PaintEventArgs e, which is a parameter of xref:System.Windows.Forms.PaintEventHandler. In addition, you should import the xref:System.Drawing.Text namespace.

See also