Font Constructors

Definition

Initializes a new Font that uses the specified existing Font and FontStyle.

Overloads

Font(Font, FontStyle)

Initializes a new Font that uses the specified existing Font and FontStyle enumeration.

Font(String, Single, FontStyle, GraphicsUnit, Byte, Boolean)

Initializes a new Font using the specified size, style, unit, and character set.

Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte, Boolean)

Initializes a new Font using a specified size, style, unit, and character set.

Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte)

Initializes a new Font using a specified size, style, unit, and character set.

Font(String, Single, FontStyle, GraphicsUnit)

Initializes a new Font using a specified size, style, and unit.

Font(FontFamily, Single, FontStyle, GraphicsUnit)

Initializes a new Font using a specified size, style, and unit.

Font(String, Single, FontStyle, GraphicsUnit, Byte)

Initializes a new Font using a specified size, style, unit, and character set.

Font(String, Single, FontStyle)

Initializes a new Font using a specified size and style.

Font(FontFamily, Single, GraphicsUnit)

Initializes a new Font using a specified size and unit. Sets the style to Regular.

Font(FontFamily, Single, FontStyle)

Initializes a new Font using a specified size and style.

Font(String, Single)

Initializes a new Font using a specified size.

Font(FontFamily, Single)

Initializes a new Font using a specified size.

Font(String, Single, GraphicsUnit)

Initializes a new Font using a specified size and unit. The style is set to Regular.

Font(Font, FontStyle)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font that uses the specified existing Font and FontStyle enumeration.

public Font (System.Drawing.Font prototype, System.Drawing.FontStyle newStyle);

Parameters

prototype
Font

The existing Font from which to create the new Font.

newStyle
FontStyle

The FontStyle to apply to the new Font. Multiple values of the FontStyle enumeration can be combined with the OR operator.

Examples

The following code example demonstrates the Inequality operator, the Font constructor, and the Bold property. This example is designed to be used with a Windows Form that contains a button named Button2. Paste the following code into your form and associate the Button2_Click method with the button's Click event.

private void Button2_Click(System.Object sender, System.EventArgs e)
{

    if (this.BackColor != SystemColors.ControlDark)
    {
        this.BackColor = SystemColors.ControlDark;
    }
    if (!(this.Font.Bold))
    {
        this.Font = new Font(this.Font, FontStyle.Bold);
    }
}

Remarks

For localized applications that are based on the .NET Framework 2.0 and earlier releases, specifying a font for prototype when that font has not been installed on the computer that is used to build your application will cause the Microsoft Sans Serif font to be used instead. If your application depends on this behavior and you must recompile your application for the .NET Framework 3.0, you should specify the Microsoft Sans Serif font for prototype.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Font(String, Single, FontStyle, GraphicsUnit, Byte, Boolean)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using the specified size, style, unit, and character set.

public Font (string familyName, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont);

Parameters

familyName
String

A string representation of the FontFamily for the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

style
FontStyle

The FontStyle of the new font.

unit
GraphicsUnit

The GraphicsUnit of the new font.

gdiCharSet
Byte

A Byte that specifies a GDI character set to use for this font.

gdiVerticalFont
Boolean

A Boolean value indicating whether the new Font is derived from a GDI vertical font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

Remarks

The gdiCharSet parameter takes a value from the list defined in the Windows SDK header file WinGDI.h. If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

See also

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte, Boolean)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size, style, unit, and character set.

public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont);

Parameters

family
FontFamily

The FontFamily of the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

style
FontStyle

The FontStyle of the new font.

unit
GraphicsUnit

The GraphicsUnit of the new font.

gdiCharSet
Byte

A Byte that specifies a

GDI character set to use for this font.

gdiVerticalFont
Boolean

A Boolean value indicating whether the new font is derived from a GDI vertical font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

family is null

Remarks

The gdiCharSet parameter takes a value from the list defined in the Windows SDK header file WinGDI.h.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size, style, unit, and character set.

public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit, byte gdiCharSet);

Parameters

family
FontFamily

The FontFamily of the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

style
FontStyle

The FontStyle of the new font.

unit
GraphicsUnit

The GraphicsUnit of the new font.

gdiCharSet
Byte

A Byte that specifies a

GDI character set to use for the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

family is null.

Remarks

The gdiCharSet parameter takes a value from the list defined in the Windows SDK header file WinGDI.h.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Font(String, Single, FontStyle, GraphicsUnit)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size, style, and unit.

public Font (string familyName, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit);

Parameters

familyName
String

A string representation of the FontFamily for the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

style
FontStyle

The FontStyle of the new font.

unit
GraphicsUnit

The GraphicsUnit of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity or is not a valid number.

Examples

The following code example demonstrates how to use the Font constructor. This example is designed to be used with Windows Forms. To run this example, paste this code into a form that contains a button named Button2, and associate the Button2_Click method with the Click event of the button.


private void Button2_Click(System.Object sender, System.EventArgs e)
{

    Button2.Font = new Font(FontFamily.GenericMonospace, 12.0F, 
        FontStyle.Italic, GraphicsUnit.Pixel);
}

Remarks

Windows Forms applications support TrueType fonts and have limited support for OpenType fonts. If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Font(FontFamily, Single, FontStyle, GraphicsUnit)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size, style, and unit.

public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit);

Parameters

family
FontFamily

The FontFamily of the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

style
FontStyle

The FontStyle of the new font.

unit
GraphicsUnit

The GraphicsUnit of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

family is null.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Font(String, Single, FontStyle, GraphicsUnit, Byte)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size, style, unit, and character set.

public Font (string familyName, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit, byte gdiCharSet);

Parameters

familyName
String

A string representation of the FontFamily for the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

style
FontStyle

The FontStyle of the new font.

unit
GraphicsUnit

The GraphicsUnit of the new font.

gdiCharSet
Byte

A Byte that specifies a GDI character set to use for this font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

Remarks

The gdiCharSet parameter takes a value from the list defined in the Windows SDK header file WinGDI.h. Windows Forms applications support TrueType fonts and have limited support for OpenType fonts. If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

See also

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Font(String, Single, FontStyle)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size and style.

public Font (string familyName, float emSize, System.Drawing.FontStyle style);

Parameters

familyName
String

A string representation of the FontFamily for the new Font.

emSize
Single

The em-size, in points, of the new font.

style
FontStyle

The FontStyle of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

Remarks

The resulting font has its Unit property set to Point. Windows Forms applications support TrueType fonts and have limited support for OpenType fonts. If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Font(FontFamily, Single, GraphicsUnit)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size and unit. Sets the style to Regular.

public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.GraphicsUnit unit);

Parameters

family
FontFamily

The FontFamily of the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

unit
GraphicsUnit

The GraphicsUnit of the new font.

Exceptions

family is null.

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

Remarks

The resulting font has its Style property set to FontStyle.Regular.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Font(FontFamily, Single, FontStyle)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size and style.

public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.FontStyle style);

Parameters

family
FontFamily

The FontFamily of the new Font.

emSize
Single

The em-size, in points, of the new font.

style
FontStyle

The FontStyle of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

family is null.

Examples

The following code example demonstrates how to set the Font property of a button to a new, bold-style Font. This example is designed to be used with a Windows Form that contains a button named Button1. Paste the following code into your form and associate the Button1_Click method with the button's Click event.

private void Button1_Click(System.Object sender, System.EventArgs e)
{
    if (Button1.Font.Style != FontStyle.Bold)
            Button1.Font = new Font(FontFamily.GenericSansSerif,
            12.0F, FontStyle.Bold);
}

Remarks

The resulting font has its Unit property set to Point.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Font(String, Single)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size.

public Font (string familyName, float emSize);

Parameters

familyName
String

A string representation of the FontFamily for the new Font.

emSize
Single

The em-size, in points, of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity or is not a valid number.

Examples

The following code example demonstrates how to use the Font constructor. This example is designed to be used with a Windows Form and requires a PaintEventArgs e, which is a parameter of the Paint event.

private void ConstructFontWithString(PaintEventArgs e)
{
    Font font1 = new Font("Arial", 20);
    e.Graphics.DrawString("Arial Font", font1, Brushes.Red, new PointF(10, 10));
}

Remarks

The resulting font has its Style property set to FontStyle.Regular and its Unit property set to GraphicsUnit.Point. Windows Forms applications support TrueType fonts and have limited support for OpenType fonts. If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Font(FontFamily, Single)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size.

public Font (System.Drawing.FontFamily family, float emSize);

Parameters

family
FontFamily

The FontFamily of the new Font.

emSize
Single

The em-size, in points, of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

Remarks

The resulting font has its Style property set to Regular and its Unit property set to Point.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Font(String, Single, GraphicsUnit)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size and unit. The style is set to Regular.

public Font (string familyName, float emSize, System.Drawing.GraphicsUnit unit);

Parameters

familyName
String

A string representation of the FontFamily for the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

unit
GraphicsUnit

The GraphicsUnit of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

Remarks

The resulting font has its Style property set to FontStyle.Regular.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9