Lire en anglais

Partager via


Graphics.TextRenderingHint Propriété

Définition

Obtient ou définit le mode de rendu du texte associé à ce Graphics.

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

Valeur de propriété

Une des valeurs de l'objet TextRenderingHint.

Exemples

L’exemple de code suivant illustre l’utilisation des TextRenderingHint propriétés et TextContrast .

Cet exemple est conçu pour être utilisé avec Windows Forms. Collez le code dans un formulaire et appelez la méthode lors de la ChangeTextRenderingHintAndTextContrast gestion de l’événement du Paint formulaire, en passant e comme 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();
}

Remarques

L’indicateur de rendu de texte spécifie si le texte est rendu avec anti-attirail.

Note

Vous ne devez pas utiliser la CompositingMode valeur de la propriété de SourceCopy lorsque la TextRenderingHint propriété a la valeur ClearTypeGridFit. Une exception peut se produire ou l’image peut ne pas s’afficher correctement.

S’applique à

Produit Versions
.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