SALES: 1-800-867-1380
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Font Class

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

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

[SerializableAttribute]
[ComVisibleAttribute(true)]
[TypeConverterAttribute(typeof(FontConverter))]
public sealed class Font : MarshalByRefObject, ICloneable, 
	ISerializable, IDisposable

The Font type exposes the following members.

  NameDescription
Public methodFont(Font, FontStyle)Initializes a new Font that uses the specified existing Font and FontStyle enumeration.
Public methodFont(FontFamily, Single)Initializes a new Font using a specified size.
Public methodFont(String, Single)Initializes a new Font using a specified size.
Public methodFont(FontFamily, Single, FontStyle)Initializes a new Font using a specified size and style.
Public methodFont(FontFamily, Single, GraphicsUnit)Initializes a new Font using a specified size and unit. Sets the style to FontStyle.Regular.
Public methodFont(String, Single, FontStyle)Initializes a new Font using a specified size and style.
Public methodFont(String, Single, GraphicsUnit)Initializes a new Font using a specified size and unit. The style is set to FontStyle.Regular.
Public methodFont(FontFamily, Single, FontStyle, GraphicsUnit)Initializes a new Font using a specified size, style, and unit.
Public methodFont(String, Single, FontStyle, GraphicsUnit)Initializes a new Font using a specified size, style, and unit.
Public methodFont(FontFamily, Single, FontStyle, GraphicsUnit, Byte)Initializes a new Font using a specified size, style, unit, and character set.
Public methodFont(String, Single, FontStyle, GraphicsUnit, Byte)Initializes a new Font using a specified size, style, unit, and character set.
Public methodFont(FontFamily, Single, FontStyle, GraphicsUnit, Byte, Boolean)Initializes a new Font using a specified size, style, unit, and character set.
Public methodFont(String, Single, FontStyle, GraphicsUnit, Byte, Boolean)Initializes a new Font using the specified size, style, unit, and character set.
Top

  NameDescription
Public propertyBoldGets a value that indicates whether this Font is bold.
Public propertyFontFamilyGets the FontFamily associated with this Font.
Public propertyGdiCharSetGets a byte value that specifies the GDI character set that this Font uses.
Public propertyGdiVerticalFontGets a Boolean value that indicates whether this Font is derived from a GDI vertical font.
Public propertyHeightGets the line spacing of this font.
Public propertyIsSystemFontGets a value indicating whether the font is a member of SystemFonts.
Public propertyItalicGets a value that indicates whether this font has the italic style applied.
Public propertyNameGets the face name of this Font.
Public propertyOriginalFontNameInfrastructure. Gets the name of the font originally specified.
Public propertySizeGets the em-size of this Font measured in the units specified by the Unit property.
Public propertySizeInPointsGets the em-size, in points, of this Font.
Public propertyStrikeoutGets a value that indicates whether this Font specifies a horizontal line through the font.
Public propertyStyleGets style information for this Font.
Public propertySystemFontNameGets the name of the system font if the IsSystemFont property returns true.
Public propertyUnderlineGets a value that indicates whether this Font is underlined.
Public propertyUnitGets the unit of measure for this Font.
Top

  NameDescription
Public methodCloneCreates an exact copy of this Font.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodDisposeReleases all resources used by this Font.
Public methodEqualsIndicates whether the specified object is a Font and has the same FontFamily, GdiVerticalFont, GdiCharSet, Style, Size, and Unit property values as this Font. (Overrides Object.Equals(Object).)
Public methodStatic memberFromHdcCreates a Font from the specified Windows handle to a device context.
Public methodStatic memberFromHfontCreates a Font from the specified Windows handle.
Public methodStatic memberFromLogFont(Object)Creates a Font from the specified GDI logical font (LOGFONT) structure.
Public methodStatic memberFromLogFont(Object, IntPtr)Creates a Font from the specified GDI logical font (LOGFONT) structure.
Public methodGetHashCodeGets the hash code for this Font. (Overrides Object.GetHashCode().)
Public methodGetHeight()Returns the line spacing, in pixels, of this font.
Public methodGetHeight(Graphics)Returns the line spacing, in the current unit of a specified Graphics, of this font.
Public methodGetHeight(Single)Returns the height, in pixels, of this Font when drawn to a device with the specified vertical resolution.
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodToHfontReturns a handle to this Font.
Public methodToLogFont(Object)Creates a GDI logical font (LOGFONT) structure from this Font.
Public methodToLogFont(Object, Graphics)Creates a GDI logical font (LOGFONT) structure from this Font.
Public methodToStringReturns a human-readable string representation of this Font. (Overrides Object.ToString().)
Top

  NameDescription
Explicit interface implemetationPrivate methodISerializable.GetObjectDataPopulates a SerializationInfo with the data needed to serialize the target object.
Top

For more information about how to construct fonts, see How to: Construct Font Families and Fonts. Windows Forms applications support TrueType fonts and have limited support for OpenType fonts. If you attempt to use a font that is not supported, or the font is not installed on the machine that is running the application, the Microsoft Sans Serif font will be substituted.

The following code example demonstrates how to use the Font constructor and the Size, SizeInPoints, and Unit properties. This example is designed to be used with a Windows Form that contains a ComboBox named ComboBox1 that is populated with the strings "Bigger" and "Smaller" and a Label named Label1. Paste the following code into the form and associate the ComboBox1_SelectedIndexChanged method with the SelectedIndexChanged event of the ComboBox control.

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

    // Cast the sender object back to a ComboBox.
    ComboBox ComboBox1 = (ComboBox) sender;

    // Retrieve the selected item. 
    string selectedString = (string) ComboBox1.SelectedItem;

    // Convert it to lowercase.
    selectedString = selectedString.ToLower();

    // Declare the current size. 
    float currentSize;

    // Switch on the selected item.  
    switch(selectedString)
    {

            // If Bigger is selected, get the current size from the  
            // Size property and increase it. Reset the font to the 
            //  new size, using the current unit. 
        case "bigger":
            currentSize = Label1.Font.Size;
            currentSize += 2.0F;
            Label1.Font = new Font(Label1.Font.Name, currentSize, 
                Label1.Font.Style, Label1.Font.Unit);

            // If Smaller is selected, get the current size, in points, 
            // and decrease it by 1.  Reset the font with the new size 
            // in points. 
            break;
        case "smaller":
            currentSize = Label1.Font.SizeInPoints;
            currentSize -= 1;
            Label1.Font = new Font(Label1.Font.Name, currentSize, 
                Label1.Font.Style);
            break;
    }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft