Graphics.TextRenderingHint Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene o establece el modo de representación para el texto asociado a este 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
Valor de propiedad
Uno de los valores de TextRenderingHint.
Ejemplos
En el ejemplo de código siguiente se muestra el uso de las TextRenderingHint propiedades y TextContrast .
Este ejemplo está diseñado para usarse con Windows Forms. Pegue el código en un formulario y llame al ChangeTextRenderingHintAndTextContrast
método al controlar el evento del Paint formulario, pasando e
como 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
Comentarios
La sugerencia de representación de texto especifica si el texto se representa con suavizado de contorno.
Nota
No debe usar un CompositingMode valor de propiedad de SourceCopy cuando la TextRenderingHint propiedad se establece ClearTypeGridFiten . Se puede producir una excepción o es posible que la imagen no se represente correctamente.