Ler em inglês

Partilhar via


Graphics.TextRenderingHint Propriedade

Definição

Obtém ou define o modo de renderização para o texto associado a este Graphics.

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

Valor da propriedade

Um dos valores de TextRenderingHint.

Exemplos

O exemplo de código a seguir demonstra o uso das TextRenderingHint propriedades e TextContrast .

Este exemplo foi projetado para ser usado com Windows Forms. Cole o código em um formulário e chame o ChangeTextRenderingHintAndTextContrast método ao manipular o evento do Paint formulário, passando e como 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();
}

Comentários

A dica de renderização de texto especifica se o texto é renderizado com suavização.

Nota

Você não deve usar um CompositingMode valor de propriedade de SourceCopy quando a TextRenderingHint propriedade é definida como ClearTypeGridFit. Uma exceção pode ocorrer ou a imagem pode não ser renderizada corretamente.

Aplica-se a

Produto Versões
.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