This documentation is archived and is not being maintained.

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)

public ref class Font sealed : public MarshalByRefObject, 
	ICloneable, ISerializable, IDisposable

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.

    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;

        // 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. 
        if (selectedString == "bigger")
            currentSize = Label1->Font->Size;
            currentSize += 2.0F;
            Label1->Font =gcnew System::Drawing::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 2.  Reset the font with 
        // the new size in points. 
        if (selectedString == "smaller")
            currentSize = Label1->Font->Size;
            currentSize -= 2.0F;
            Label1->Font = gcnew System::Drawing::Font(Label1->Font->Name, 
                currentSize, Label1->Font->Style);


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0