Export (0) Print
Expand All

TextRenderingHint Enumeration

Specifies the quality of text rendering.

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

'Declaration
Public Enumeration TextRenderingHint
'Usage
Dim instance As TextRenderingHint

public enum TextRenderingHint
public enum TextRenderingHint

 Member nameDescription
AntiAliasEach character is drawn using its antialiased glyph bitmap without hinting. Better quality due to antialiasing. Stem width differences may be noticeable because hinting is turned off. 
AntiAliasGridFitEach character is drawn using its antialiased glyph bitmap with hinting. Much better quality due to antialiasing, but at a higher performance cost. 
ClearTypeGridFitEach character is drawn using its glyph ClearType bitmap with hinting. The highest quality setting. Used to take advantage of ClearType font features. 
SingleBitPerPixelEach character is drawn using its glyph bitmap. Hinting is not used. 
SingleBitPerPixelGridFitEach character is drawn using its glyph bitmap. Hinting is used to improve character appearance on stems and curvature. 
SystemDefaultEach character is drawn using its glyph bitmap, with the system default rendering hint. The text will be drawn using whatever font-smoothing settings the user has selected for the system. 

The quality ranges from text (fastest performance, but lowest quality) to antialiased text (better quality, but slower performance) to ClearType text (best quality on an LCD display).

The following code example demonstrates the use of the TextRenderingHint and TextContrast properties and the TextRenderingHint enumeration.

This example is designed to be used with Windows Forms. Paste the code into a form and call the ChangeTextRenderingHintAndTextContrast method when handling the form's Paint event, passing e as PaintEventArgs.

Private Sub ChangeTextRenderingHintAndTextContrast(ByVal e As _
    PaintEventArgs)

    ' Retrieve the graphics object.
    Dim formGraphics As Graphics = e.Graphics

    ' Declare a new font.
    Dim myFont As Font = New Font(FontFamily.GenericSansSerif, _
        20, FontStyle.Regular)

    ' Set the TextRenderingHint property.
    formGraphics.TextRenderingHint = _
        System.Drawing.Text.TextRenderingHint.SingleBitPerPixel

    ' Draw the string.
    formGraphics.DrawString("Hello World", myFont, _
        Brushes.Firebrick, 20.0F, 20.0F)

    ' Change the TextRenderingHint property.
    formGraphics.TextRenderingHint = _
        System.Drawing.Text.TextRenderingHint.AntiAliasGridFit

    ' Draw the string again.
    formGraphics.DrawString("Hello World", myFont, _
        Brushes.Firebrick, 20.0F, 60.0F)

    ' Set the text contrast to a high-contrast setting.
    formGraphics.TextContrast = 0

    ' Draw the string.
    formGraphics.DrawString("Hello World", myFont, _
        Brushes.DodgerBlue, 20.0F, 100.0F)

    ' Set the text contrast to a low-contrast setting.
    formGraphics.TextContrast = 12

    ' Draw the string again.
    formGraphics.DrawString("Hello World", myFont, _
        Brushes.DodgerBlue, 20.0F, 140.0F)

    ' Dispose of the font object.
    myFont.Dispose()

End Sub

private void ChangeTextRenderingHintAndTextContrast(PaintEventArgs e)
{
    // Retrieve the graphics object.
    Graphics formGraphics = e.get_Graphics();

    // Declare a new font.
    Font myFont = new Font(FontFamily.get_GenericSansSerif(), 
                20, FontStyle.Regular);

    // Set the TextRenderingHint property.
    formGraphics.set_TextRenderingHint(System.Drawing.Text.
        TextRenderingHint.SingleBitPerPixel);

    // Draw the string.
    formGraphics.DrawString("Hello World", myFont,
        Brushes.get_Firebrick(), 20, 20);

    // Change the TextRenderingHint property.
    formGraphics.set_TextRenderingHint(System.Drawing.Text.
        TextRenderingHint.AntiAliasGridFit);

    // Draw the string again.
    formGraphics.DrawString("Hello World", myFont, 
        Brushes.get_Firebrick(), 20, 60);

    // Set the text contrast to a high-contrast setting.
    formGraphics.set_TextContrast(0);

    // Draw the string.
    formGraphics.DrawString("Hello World", myFont, 
        Brushes.get_DodgerBlue(), 20, 100);

    // Set the text contrast to a low-contrast setting.
    formGraphics.set_TextContrast(12);

    // Draw the string again.
    formGraphics.DrawString("Hello World", myFont,
        Brushes.get_DodgerBlue(), 20, 140);

    // Dispose of the font object.
    myFont.Dispose();
} //ChangeTextRenderingHintAndTextContrast

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