This documentation is archived and is not being maintained.

FontConverter Class

Converts Font objects from one data type to another.

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

Public Class FontConverter
	Inherits TypeConverter
Dim instance As FontConverter

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

Access the FontConverter class through the TypeDescriptor object.

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 Sub ShowFontStringConversion(ByVal e As PaintEventArgs)

    ' Create the FontConverter.
    Dim converter As System.ComponentModel.TypeConverter = _

    Dim font1 As Font = _
        CType(converter.ConvertFromString("Arial, 12pt"), Font)

    Dim fontName1 As String = _
    Dim fontName2 As String = converter.ConvertToString(font1)

    e.Graphics.DrawString(fontName1, font1, Brushes.Red, 10, 10)
    e.Graphics.DrawString(fontName2, font1, Brushes.Blue, 10, 30)
End Sub

private void ShowFontStringConversion(PaintEventArgs e)
    // Create the FontConverter.
    System.ComponentModel.TypeConverter converter = 
    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, 
    e.get_Graphics().DrawString(fontName2, font1, Brushes.get_Blue(), 10,
} //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