TextRenderingHint 枚举

指定文本呈现的质量。

**命名空间:**System.Drawing.Text
**程序集:**System.Drawing(在 system.drawing.dll 中)

语法

声明
Public Enumeration TextRenderingHint
用法
Dim instance As TextRenderingHint
public enum TextRenderingHint
public enum class TextRenderingHint
public enum TextRenderingHint
public enum TextRenderingHint

成员

  成员名称 说明
AntiAlias 在无提示的情况下使用每个字符的消除锯齿效果标志符号位图来绘制字符。由于采用了 AntiAlias,质量会得到改善。由于关闭了提示,主干宽度差可能会比较明显。 
AntiAliasGridFit 在有提示的情况下使用每个字符的消除锯齿效果标志符号位图来绘制字符。由于采用了 AntiAlias,质量会得到大大改善,但同时会增加性能成本。 
ClearTypeGridFit 在有提示的情况下使用每个字符的标志符号 ClearType 位图来绘制字符。这是质量最高的设置。用于利用 ClearType 字体功能。 
SingleBitPerPixel 使用每个字符的标志符号位图来绘制字符。不使用提示。 
SingleBitPerPixelGridFit 使用每个字符的标志符号位图来绘制字符。提示用于改善字符在主干和弯曲部分的外观。 
SystemDefault 在有系统默认呈现提示的情况下使用每个字符的标志符号位图来绘制字符。将采用用户为系统选择的任何字体修匀设置来绘制文本。 

备注

质量选项包括文本(速度最快但质量最低)、消除锯齿效果文本(质量较好但速度较慢)以及 ClearType 文本(在 LCD 显示器上质量最佳)。

示例

下面的代码示例演示了如何使用 TextRenderingHintTextContrast 属性以及 TextRenderingHint 枚举。

此示例是针对使用 Windows 窗体而设计的。将代码粘贴到一个窗体中,然后在处理窗体的 Paint 事件时调用 ChangeTextRenderingHintAndTextContrast 方法,并传递 e 作为 PaintEventArgs

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
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:
   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.get_Graphics();

    // Declare a new font.
    Font myFont = new Font(FontFamily.get_GenericSansSerif(), 
                20, FontStyle.Regular);

    // Set the TextRenderingHint property.
    formGraphics.set_TextRenderingHint(System.Drawing.Text.
        TextRenderingHint.SingleBitPerPixel);

    // Draw the string.
    formGraphics.DrawString("Hello World", myFont,
        Brushes.get_Firebrick(), 20, 20);

    // Change the TextRenderingHint property.
    formGraphics.set_TextRenderingHint(System.Drawing.Text.
        TextRenderingHint.AntiAliasGridFit);

    // Draw the string again.
    formGraphics.DrawString("Hello World", myFont, 
        Brushes.get_Firebrick(), 20, 60);

    // Set the text contrast to a high-contrast setting.
    formGraphics.set_TextContrast(0);

    // Draw the string.
    formGraphics.DrawString("Hello World", myFont, 
        Brushes.get_DodgerBlue(), 20, 100);

    // Set the text contrast to a low-contrast setting.
    formGraphics.set_TextContrast(12);

    // Draw the string again.
    formGraphics.DrawString("Hello World", myFont,
        Brushes.get_DodgerBlue(), 20, 140);

    // Dispose of the font object.
    myFont.Dispose();
} //ChangeTextRenderingHintAndTextContrast

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

System.Drawing.Text 命名空间