Export (0) Print
Expand All

FontConverter Class

Converts Font objects from one data type to another.

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

public class FontConverter : TypeConverter
public class FontConverter extends TypeConverter
public class FontConverter extends TypeConverter
Not applicable.

A type converter is used to convert values between data types. A type converter also supports property configuration at design time by providing text-to-value conversion or a list of values that users can select from. Access the FontConverter class through the TypeDescriptor class by calling the GetConverter method.

The following code example demonstrates how to use the FontConverter to convert a Font to and from a string. This example is designed to be used with Windows Forms. Paste this code into a form and call the ShowFontStringConversion method when handling the form's Paint event, passing e as PaintEventArgs.

private void ShowFontStringConversion(PaintEventArgs e)
{

    // Create the FontConverter.
    System.ComponentModel.TypeConverter converter = 
        System.ComponentModel.TypeDescriptor.GetConverter(typeof(Font));

    Font font1 = (Font) converter.ConvertFromString("Arial, 12pt");

    string fontName1 = converter.ConvertToInvariantString(font1);
    string fontName2 = converter.ConvertToString(font1);

    e.Graphics.DrawString(fontName1, font1, Brushes.Red, 10, 10);
    e.Graphics.DrawString(fontName2, font1, Brushes.Blue, 10, 30);
}

private void ShowFontStringConversion(PaintEventArgs e)
{
    // Create the FontConverter.
    System.ComponentModel.TypeConverter converter = 
        System.ComponentModel.TypeDescriptor.GetConverter(
        get_Font().GetType());
    Font font1 = (Font)(converter.ConvertFromString("Arial, 12pt"));
    String fontName1 = converter.ConvertToInvariantString(font1);
    String fontName2 = converter.ConvertToString(font1);

    e.get_Graphics().DrawString(fontName1, font1, Brushes.get_Red(), 10, 
        10);
    e.get_Graphics().DrawString(fontName2, font1, Brushes.get_Blue(), 10,
        30);
} //ShowFontStringConversion

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 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft