Font

System.Drawing.Font

Namespace: System.Drawing

Assembly: System.Drawing.Managed (4.0.0.0)

Defines a particular format for text, including font face, size, and style attributes. This class cannot be inherited.

public class Font : MarshalByRefObject, ICloneable, IDisposable, ISerializable

Constructors

Font(familyName, emSize)

Initializes a new instance of the Font class.

Name
Type
Description

familyName

A string representation of the FontFamily for the new Font.

emSize

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

Throws:

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

Font(familyName, emSize, style)

Initializes a new instance of the Font class.

Name
Type
Description

familyName

A string representation of the FontFamily for the new Font.

emSize

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

style

The FontStyle of the new font.

Throws:

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

Font(familyName, emSize, unit)

Initializes a new instance of the Font class.

Name
Type
Description

familyName

A string representation of the FontFamily for the new Font.

emSize

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

unit

The GraphicsUnit of the new font.

Throws:

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

Font(familyName, emSize, style, unit)

Initializes a new instance of the Font class.

Name
Type
Description

familyName

A string representation of the FontFamily for the new Font.

emSize

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

style

The FontStyle of the new font.

unit

The GraphicsUnit of the new font.

Throws:

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

Font(familyName, emSize, style, unit, gdiCharSet)

Initializes a new instance of the Font class.

Name
Type
Description

familyName

A string representation of the FontFamily for the new Font.

emSize

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

style

The FontStyle of the new font.

unit

The GraphicsUnit of the new font.

gdiCharSet

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

Throws:

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

Font(familyName, emSize, style, unit, gdiCharSet, gdiVerticalFont)

Initializes a new instance of the Font class.

Name
Type
Description

familyName

A string representation of the FontFamily for the new Font.

emSize

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

style

The FontStyle of the new font.

unit

The GraphicsUnit of the new font.

gdiCharSet

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

gdiVerticalFont

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

Throws:

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

Font(prototype, newStyle)

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

Name
Type
Description

prototype

The existing Font from which to create the new Font.

newStyle

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

Font(family, emSize)

Initializes a new instance of the Font class.

Name
Type
Description

family

The FontFamily of the new Font.

emSize

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

Throws:

Font(family, emSize, style)

Initializes a new instance of the Font class.

Name
Type
Description

family

The FontFamily of the new Font.

emSize

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

style

The FontStyle of the new font.

Throws:

Font(family, emSize, unit)

Initializes a new instance of the Font class.

Name
Type
Description

family

The FontFamily of the new Font.

emSize

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

unit

The GraphicsUnit of the new font.

Throws:

Font(family, emSize, style, unit)

Initializes a new instance of the Font class.

Name
Type
Description

family

The FontFamily of the new Font.

emSize

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

style

The FontStyle of the new font.

unit

The GraphicsUnit of the new font.

Throws:

Font(family, emSize, style, unit, gdiCharSet)

Initializes a new instance of the Font class.

Name
Type
Description

family

The FontFamily of the new Font.

emSize

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

style

The FontStyle of the new font.

unit

The GraphicsUnit of the new font.

gdiCharSet

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

Throws:

Font(family, emSize, style, unit, gdiCharSet, gdiVerticalFont)

Initializes a new instance of the Font class.

Name
Type
Description

family

The FontFamily of the new Font.

emSize

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

style

The FontStyle of the new font.

unit

The GraphicsUnit of the new font.

gdiCharSet

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

gdiVerticalFont

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

Throws:

Properties

Bold

Boolean: Gets a value indicating whether this Font is bold.

FontFamily

FontFamily: Gets the FontFamily associated with this Font.

GdiCharSet

Byte: Gets a byte value that specifies the GDI character set that this Font uses.

This property returns 1, unless a different character set is specified in the Font(String, Single, FontStyle, GraphicsUnit, Byte) constructor. This property takes a value from the list defined in the Windows SDK header file WinGDI.h. The character sets and byte values are listed in the following table. system.drawing.font

GdiVerticalFont

Boolean: Gets a value indicating whether this Font is derived from a GDI vertical font.

Use this property to determine if a font is compatible with native Win32 controls on non-Unicode platforms. GdiVerticalFont only returns true if this font was created from a classic GDI font definition, like a LOGFONT or HFONT.

Height

Int32: Gets the line spacing of this font.

IsSystemFont

Boolean: Gets a value indicating whether the font is a member of SystemFonts.

Italic

Boolean: Gets a value indicating whether this Font is italic.

Name

String: Gets the face name of this Font.

OriginalFontName

String: Gets the name of the font originally specified.

The actual font name and original font name can be different. System requirements may cause the use of a font other than the font originally specified.

Size

Single: Gets the em-size of this Font measured in the units specified by the Unit property.

SizeInPoints

Single: Gets the em-size, in points, of this Font.

Strikeout

Boolean: Gets a value indicating whether this Font specifies a horizontal line through the font.

Style

FontStyle: Gets style information for this Font.

SystemFontName

String: Gets the name of the system font if the IsSystemFont property returns true.

Underline

Boolean: Gets a value indicating whether this Font is underlined.

Unit

GraphicsUnit: Gets the unit of measure for this Font.

Methods

Clone()

Returns: Object.

Dispose()

Finalize()

Finalizes an instance of the Font class.

GetHeight()

Returns the line spacing of this font.

Returns: Single. The line spacing, in pixels, of this font.

GetHeight(graphics)

Returns the line spacing, in the current unit of a specified Graphics, of this font.

Parameter
Type
Description

graphics

A Graphics that holds the vertical resolution, in dots per inch, of the display device as well as settings for page unit and page scale.

Returns: Single. The line spacing, in the graphics unit, of this font.

GetHeight(dpi)

Returns the height, in pixels, of this Font when drawn to a device with the specified vertical resolution.

Parameter
Type
Description

dpi

The vertical resolution, in dots per inch, used to calculate the height of the font.

Returns: Single. The height, in pixels, of this Font.

Last updated

Was this helpful?