Draws the specified text at the specified location using the specified device context, font, and color.
Namespace:
System.Windows.Forms
Assembly:
System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
Public Shared Sub DrawText ( _
dc As IDeviceContext, _
text As String, _
font As Font, _
pt As Point, _
foreColor As Color _
)
Dim dc As IDeviceContext
Dim text As String
Dim font As Font
Dim pt As Point
Dim foreColor As Color
TextRenderer.DrawText(dc, text, font, pt, foreColor)
public static void DrawText(
IDeviceContext dc,
string text,
Font font,
Point pt,
Color foreColor
)
public:
static void DrawText(
IDeviceContext^ dc,
String^ text,
Font^ font,
Point pt,
Color foreColor
)
public static function DrawText(
dc : IDeviceContext,
text : String,
font : Font,
pt : Point,
foreColor : Color
)
| Exception | Condition |
|---|
| ArgumentNullException |
dc is nullNothingnullptra null reference (Nothing in Visual Basic). |
You can manipulate how the text is drawn by using one of the DrawText overloads that takes a TextFormatFlags parameter.
If font is nullNothingnullptra null reference (Nothing in Visual Basic) or forecolor is Color..::.Empty, 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.
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.
Note: |
|---|
The DrawText methods that specify a Point as the upper-left corner of the drawn text do not render correctly on Windows 2000. If your application is intended for use on machines running Windows 2000, you should use one of the DrawText methods that specify a Rectangle for the bounds of the drawn text. |
The following code example demonstrates how to use the DrawText method. To run this example, paste the code into a Windows Form and call RenderText1 from the form's Paint event handler, passing e as PaintEventArgs.
Private Sub RenderText1(ByVal e As PaintEventArgs)
TextRenderer.DrawText(e.Graphics, "Regular Text", _
Me.Font, New Point(10, 10), SystemColors.ControlText)
End Sub
private void RenderText1(PaintEventArgs e)
{
TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font,
new Point(10, 10), SystemColors.ControlText);
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
Reference