TextRenderingHint 枚举

定义

指定文本呈现的质量。Specifies the quality of text rendering.

public enum class TextRenderingHint
public enum TextRenderingHint
type TextRenderingHint = 
Public Enum TextRenderingHint
继承
TextRenderingHint

字段

AntiAlias 4

在无提示的情况下使用每个字符的抗锯齿效果标志符号位图来绘制字符。Each character is drawn using its antialiased glyph bitmap without hinting. 由于采用了 AntiAlias,质量会得到改善。Better quality due to antialiasing. 由于关闭了提示,主干宽度差可能会比较明显。Stem width differences may be noticeable because hinting is turned off.

AntiAliasGridFit 3

在有提示的情况下使用每个字符的抗锯齿效果标志符号位图来绘制字符。Each character is drawn using its antialiased glyph bitmap with hinting. 由于采用了 AntiAlias,质量会得到大大改善,但同时会增加性能成本。Much better quality due to antialiasing, but at a higher performance cost.

ClearTypeGridFit 5

在有提示的情况下使用每个字符的标志符号 ClearType 位图来绘制字符。Each character is drawn using its glyph ClearType bitmap with hinting. 这是质量最高的设置。The highest quality setting. 用于利用 ClearType 字体功能。Used to take advantage of ClearType font features.

SingleBitPerPixel 2

使用每个字符的标志符号位图来绘制字符。Each character is drawn using its glyph bitmap. 不使用提示。Hinting is not used.

SingleBitPerPixelGridFit 1

使用每个字符的标志符号位图来绘制字符。Each character is drawn using its glyph bitmap. 提示用于改善字符在主干和弯曲部分的外观。Hinting is used to improve character appearance on stems and curvature.

SystemDefault 0

在有系统默认呈现提示的情况下使用每个字符的标志符号位图来绘制字符。Each character is drawn using its glyph bitmap, with the system default rendering hint. 将采用用户为系统选择的任何字体修匀设置来绘制文本。The text will be drawn using whatever font-smoothing settings the user has selected for the system.

示例

下面的代码示例演示如何使用TextRenderingHintTextContrast属性以及TextRenderingHint枚举。The following code example demonstrates the use of the TextRenderingHint and TextContrast properties and the TextRenderingHint enumeration.

此示例旨在与 Windows 窗体一起使用。This example is designed to be used with Windows Forms. 将代码粘贴到窗体中, 并ChangeTextRenderingHintAndTextContrast在处理Paint窗体事件时调用方法, ePaintEventArgs将作为传递。Paste the code into a form and call the ChangeTextRenderingHintAndTextContrast method when handling the form's Paint event, passing e as PaintEventArgs.

private:
   void ChangeTextRenderingHintAndTextContrast( PaintEventArgs^ e )
   {
      // Retrieve the graphics object.
      Graphics^ formGraphics = e->Graphics;

      // Declare a new font.
      System::Drawing::Font^ myFont = gcnew System::Drawing::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.
      delete myFont;
   }
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();

}
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

注解

质量范围从文本 (性能最高, 但质量最低) 到 ClearType 文本 (更好的质量, 但性能较低) 到 ClearType 文本 (在 LCD 显示器上的最佳质量)。The quality ranges from text (fastest performance, but lowest quality) to antialiased text (better quality, but slower performance) to ClearType text (best quality on an LCD display).

适用于