Graphics.TextRenderingHint 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定與這個 Graphics 關聯之文字的呈現模式。
public:
property System::Drawing::Text::TextRenderingHint TextRenderingHint { System::Drawing::Text::TextRenderingHint get(); void set(System::Drawing::Text::TextRenderingHint value); };
public System.Drawing.Text.TextRenderingHint TextRenderingHint { get; set; }
member this.TextRenderingHint : System.Drawing.Text.TextRenderingHint with get, set
Public Property TextRenderingHint As TextRenderingHint
屬性值
其中一個 TextRenderingHint 值。
範例
下列程式代碼範例示範 如何使用 TextRenderingHint 和 TextContrast 屬性。
此範例的設計目的是要與 Windows Forms 搭配使用。 將程式代碼貼到表單中,並在處理表單的事件時呼叫 ChangeTextRenderingHintAndTextContrast
方法,並e
傳遞為 PaintEventArgs。Paint
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
備註
文字轉譯提示會指定文字是否以反鋸齒呈現。
注意
當 屬性設定為 ClearTypeGridFit時TextRenderingHint,您不應該使用 CompositingMode 的SourceCopy屬性值。 可能發生例外狀況,或影像可能無法正確轉譯。