Files
docs-desktop/dotnet-desktop-guide/framework/winforms/advanced/how-to-construct-font-families-and-fonts.md
T
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.5 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Construct Font Families and Fonts 03/30/2017
csharp
vb
font families [Windows Forms], constructing
fonts [Windows Forms], constructing
d3a4a223-9492-4b54-9afd-db1c31c3cefd

How to: Construct Font Families and Fonts

GDI+ groups fonts with the same typeface but different styles into font families. For example, the Arial font family contains the following fonts:

  • Arial Regular

  • Arial Bold

  • Arial Italic

  • Arial Bold Italic

GDI+ uses four styles to form families: regular, bold, italic, and bold italic. Adjectives such as narrow and rounded are not considered styles; rather they are part of the family name. For example, Arial Narrow is a font family with the following members:

  • Arial Narrow Regular

  • Arial Narrow Bold

  • Arial Narrow Italic

  • Arial Narrow Bold Italic

Before you can draw text with GDI+, you need to construct a xref:System.Drawing.FontFamily object and a xref:System.Drawing.Font object. The xref:System.Drawing.FontFamily object specifies the typeface (for example, Arial), and the xref:System.Drawing.Font object specifies the size, style, and units.

Example

The following example constructs a regular style Arial font with a size of 16 pixels. In the following code, the first argument passed to the xref:System.Drawing.Font.%23ctor%2A constructor is the xref:System.Drawing.FontFamily object. The second argument specifies the size of the font measured in units identified by the fourth argument. The third argument identifies the style.

xref:System.Drawing.GraphicsUnit.Pixel is a member of the xref:System.Drawing.GraphicsUnit enumeration, and xref:System.Drawing.FontStyle.Regular is a member of the xref:System.Drawing.FontStyle enumeration.

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

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.

See also