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]
[TypeConverterAttribute(typeof(FontConverter))]
[ComVisibleAttribute(true)]
public sealed class Font : MarshalByRefObject, ICloneable, ISerializable, 
	IDisposable

NameDescription
System_CAPS_pubmethodFont(Font, FontStyle)

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

System_CAPS_pubmethodFont(FontFamily, Single)

Initializes a new Font using a specified size.

System_CAPS_pubmethodFont(FontFamily, Single, FontStyle)

Initializes a new Font using a specified size and style.

System_CAPS_pubmethodFont(FontFamily, Single, FontStyle, GraphicsUnit)

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

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

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

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

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

System_CAPS_pubmethodFont(FontFamily, Single, GraphicsUnit)

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

System_CAPS_pubmethodFont(String, Single)

Initializes a new Font using a specified size.

System_CAPS_pubmethodFont(String, Single, FontStyle)

Initializes a new Font using a specified size and style.

System_CAPS_pubmethodFont(String, Single, FontStyle, GraphicsUnit)

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

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

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

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

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

System_CAPS_pubmethodFont(String, Single, GraphicsUnit)

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

NameDescription
System_CAPS_pubpropertyBold

Gets a value that indicates whether this Font is bold.

System_CAPS_pubpropertyFontFamily

Gets the FontFamily associated with this Font.

System_CAPS_pubpropertyGdiCharSet

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

System_CAPS_pubpropertyGdiVerticalFont

Gets a Boolean value that indicates whether this Font is derived from a GDI vertical font.

System_CAPS_pubpropertyHeight

Gets the line spacing of this font.

System_CAPS_pubpropertyIsSystemFont

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

System_CAPS_pubpropertyItalic

Gets a value that indicates whether this font has the italic style applied.

System_CAPS_pubpropertyName

Gets the face name of this Font.

System_CAPS_pubpropertyOriginalFontName

This API supports the product infrastructure and is not intended to be used directly from your code. Gets the name of the font originally specified.

System_CAPS_pubpropertySize

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

System_CAPS_pubpropertySizeInPoints

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

System_CAPS_pubpropertyStrikeout

Gets a value that indicates whether this Font specifies a horizontal line through the font.

System_CAPS_pubpropertyStyle

Gets style information for this Font.

System_CAPS_pubpropertySystemFontName

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

System_CAPS_pubpropertyUnderline

Gets a value that indicates whether this Font is underlined.

System_CAPS_pubpropertyUnit

Gets the unit of measure for this Font.

NameDescription
System_CAPS_pubmethodClone()

Creates an exact copy of this Font.

System_CAPS_pubmethodCreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodDispose()

Releases all resources used by this Font.

System_CAPS_pubmethodEquals(Object)

Indicates 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).)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Overrides Object.Finalize().)

System_CAPS_pubmethodSystem_CAPS_staticFromHdc(IntPtr)

Creates a Font from the specified Windows handle to a device context.

System_CAPS_pubmethodSystem_CAPS_staticFromHfont(IntPtr)

Creates a Font from the specified Windows handle.

System_CAPS_pubmethodSystem_CAPS_staticFromLogFont(Object)

Creates a Font from the specified GDI logical font (LOGFONT) structure.

System_CAPS_pubmethodSystem_CAPS_staticFromLogFont(Object, IntPtr)

Creates a Font from the specified GDI logical font (LOGFONT) structure.

System_CAPS_pubmethodGetHashCode()

Gets the hash code for this Font.(Overrides Object.GetHashCode().)

System_CAPS_pubmethodGetHeight()

Returns the line spacing, in pixels, of this font.

System_CAPS_pubmethodGetHeight(Graphics)

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

System_CAPS_pubmethodGetHeight(Single)

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

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodToHfont()

Returns a handle to this Font.

System_CAPS_pubmethodToLogFont(Object)

Creates a GDI logical font (LOGFONT) structure from this Font.

System_CAPS_pubmethodToLogFont(Object, Graphics)

Creates a GDI logical font (LOGFONT) structure from this Font.

System_CAPS_pubmethodToString()

Returns a human-readable string representation of this Font.(Overrides Object.ToString().)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodISerializable.GetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo with the data needed to serialize the target object.

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
Available since 1.1

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

Return to top
Show: