Graphics.TextRenderingHint Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur mode penyajian untuk teks yang terkait dengan ini 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
Nilai Properti
Salah TextRenderingHint satu nilai.
Contoh
Contoh kode berikut menunjukkan penggunaan TextRenderingHint properti dan TextContrast .
Contoh ini dirancang untuk digunakan dengan Formulir Windows. Tempelkan kode ke dalam formulir dan panggil ChangeTextRenderingHintAndTextContrast
metode saat menangani peristiwa formulir Paint , meneruskan e
sebagai 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
Keterangan
Petunjuk penyajian teks menentukan apakah teks dirender dengan antialiasing.
Catatan
Anda tidak boleh menggunakan CompositingMode nilai properti saat SourceCopyTextRenderingHint properti diatur ke ClearTypeGridFit. Pengecualian dapat terjadi atau gambar mungkin tidak dirender dengan benar.