Прочитать на английском

Поделиться через


Graphics.TextRenderingHint Свойство

Определение

Возвращает или задает режим отрисовки для текста, связанного с данным объектом Graphics.

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

Значение свойства

Одно из значений перечисления TextRenderingHint.

Примеры

В следующем примере кода показано использование TextRenderingHint свойств и TextContrast .

Этот пример предназначен для использования с Windows Forms. Вставьте код в форму и вызовите ChangeTextRenderingHintAndTextContrast метод при обработке события формы Paint , передавая e как PaintEventArgs.

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();
}

Комментарии

Указание отрисовки текста указывает, будет ли текст отображаться с сглаживания.

Примечание

Не следует использовать CompositingMode значение свойства , SourceCopy если свойству TextRenderingHint присвоено значение ClearTypeGridFit. Может возникнуть исключение или изображение может отображаться неправильно.

Применяется к

Продукт Версии
.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