Graphics.TextRenderingHint Proprietà

Definizione

Ottiene o imposta la modalità di rendering per il testo associata a questo oggetto Graphics.

C#
public System.Drawing.Text.TextRenderingHint TextRenderingHint { get; set; }

Valore della proprietà

Uno dei valori di TextRenderingHint.

Esempio

Nell'esempio di codice seguente viene illustrato l'uso delle TextRenderingHint proprietà e TextContrast .

Questo esempio è progettato per essere usato con Windows Forms. Incollare il codice in un modulo e chiamare il ChangeTextRenderingHintAndTextContrast metodo durante la gestione dell'evento del Paint modulo, passando e come PaintEventArgs.

C#
private void ChangeTextRenderingHintAndTextContrast(PaintEventArgs e)
{

    // Retrieve the graphics object.
    Graphics formGraphics = e.Graphics;

    // Declare a new font.
    Font myFont = 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();
}

Commenti

L'hint per il rendering del testo specifica se il testo viene eseguito con l'antialiasing.

Nota

Non è consigliabile usare un CompositingMode valore di proprietà di SourceCopy quando la TextRenderingHint proprietà è impostata su ClearTypeGridFit. Un'eccezione potrebbe verificarsi o l'immagine potrebbe non essere eseguita correttamente.

Si applica a

Prodotto Versioni
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9