TextRenderer.DrawText Method (IDeviceContext, String, Font, Rectangle, Color, Color)
Assembly: System.Windows.Forms (in system.windows.forms.dll)
public static void DrawText ( IDeviceContext dc, string text, Font font, Rectangle bounds, Color foreColor, Color backColor )
public static void DrawText ( IDeviceContext dc, String text, Font font, Rectangle bounds, Color foreColor, Color backColor )
public static function DrawText ( dc : IDeviceContext, text : String, font : Font, bounds : Rectangle, foreColor : Color, backColor : Color )
Parameters
- dc
The device context in which to draw the text.
- text
The text to draw.
- font
The Font to apply to the drawn text.
- bounds
The Rectangle that represents the bounds of the text.
- foreColor
The Color to apply to the drawn text.
- backColor
The Color to apply to the area represented by bounds.
The backColor parameter is applied to the area within the bounds parameter. If font, backcolor or forecolor is a null reference (Nothing in Visual Basic) or Empty, respectively; the DrawText method will draw the text in the font or color currently selected in the device context specified by dc. If forecolor is Transparent, the text will not be drawn.
This method will result in text that is horizontally and vertically centered in the rectangle specified by the bounds parameter. To change how the text is drawn, use a version of DrawText that takes a TextFormatFlags parameter type.
The text rendering offered by the TextRenderer class is based on GDI text rendering and is not supported for printing from Windows Forms. Instead, use the DrawString methods of the Graphics class.
The following code example demonstrates how to use the DrawText method. To run this example, paste the code into a Windows Form and call RenderText4 from the form's Paint event handler, passing e as PaintEventArgs.
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.