Graphics.TextContrast 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 nilai koreksi gamma untuk penyajian teks.
public:
property int TextContrast { int get(); void set(int value); };
public int TextContrast { get; set; }
member this.TextContrast : int with get, set
Public Property TextContrast As Integer
Nilai Properti
Nilai koreksi gamma yang digunakan untuk merender teks antialias dan ClearType.
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
Nilai koreksi gamma harus antara 0 dan 12. Nilai defaultnya adalah 4.