Export (0) Print
Expand All

Graphics.TextContrast Property

Gets or sets the gamma correction value for rendering text.

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

'Declaration
Public Property TextContrast As Integer

Property Value

Type: System.Int32
The gamma correction value used for rendering antialiased and ClearType text.

The gamma correction value must be between 0 and 12. The default value is 4.

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

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft