--- title: "How to: Create a Private Font Collection" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "private font collections [Windows Forms], creating" - "fonts [Windows Forms], creating private collections" ms.assetid: 6533d5e5-a8dc-4b76-9fc4-3bf75c8b9212 --- # How to: Create a Private Font Collection The class inherits from the abstract base class. You can use a object to maintain a set of fonts specifically for your application. A private font collection can include installed system fonts as well as fonts that have not been installed on the computer. To add a font file to a private font collection, call the method of a object. The property of a object contains an array of objects. The number of font families in a private font collection is not necessarily the same as the number of font files that have been added to the collection. For example, suppose you add the files ArialBd.tff, Times.tff, and TimesBd.tff to a collection. There will be three files but only two families in the collection because Times.tff and TimesBd.tff belong to the same family. ## Example The following example adds the following three font files to a object: - C:\\*systemroot*\Fonts\Arial.tff (Arial, regular) - C:\\*systemroot*\Fonts\CourBI.tff (Courier New, bold italic) - C:\\*systemroot*\Fonts\TimesBd.tff (Times New Roman, bold) The code retrieves an array of objects from the property of the object. For each object in the collection, the code calls the method to determine whether various styles (regular, bold, italic, bold italic, underline, and strikeout) are available. The arguments passed to the method are members of the enumeration. If a given family/style combination is available, a object is constructed using that family and style. The first argument passed to the constructor is the font family name (not a object as is the case for other variations of the constructor). After the object is constructed, it is passed to the method of the class to display the family name along with the name of the style. The output of the following code is similar to the output shown in the following illustration: ![Screenshot that shows text in various fonts.](./media/how-to-create-a-private-font-collection/various-fonts-text-output.png) Arial.tff (which was added to the private font collection in the following code example) is the font file for the Arial regular style. Note, however, that the program output shows several available styles other than regular for the Arial font family. That is because GDI+ can simulate the bold, italic, and bold italic styles from the regular style. GDI+ can also produce underlines and strikeouts from the regular style. Similarly, GDI+ can simulate the bold italic style from either the bold style or the italic style. The program output shows that the bold italic style is available for the Times family even though TimesBd.tff (Times New Roman, bold) is the only Times file in the collection. [!code-csharp[System.Drawing.FontsAndText#51](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Drawing.FontsAndText/CS/Class1.cs#51)] [!code-vb[System.Drawing.FontsAndText#51](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.FontsAndText/VB/Class1.vb#51)] ## Compiling the Code The preceding example is designed for use with Windows Forms, and it requires `e`, which is a parameter of . ## See also - - [Using Fonts and Text](using-fonts-and-text.md)