This documentation is archived and is not being maintained.

TextRenderer.DrawText Method (IDeviceContext, String, Font, Point, Color)

Note: This method is new in the .NET Framework version 2.0.

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)

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
)

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.

pt

The Point that represents the upper-left corner of the drawn text.

foreColor

The Color to apply to the drawn text.

Exception typeCondition

ArgumentNullException

dc is a 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 a 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.

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 void RenderText1(PaintEventArgs e)
{
    TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font, 
        new Point(10, 10), SystemColors.ControlText);

}

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.

.NET Framework

Supported in: 2.0
Show: