Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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

Draws the specified text at the specified location, using the specified device context, font, color, and back 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,
	Color backColor
)

Parameters

dc
Type: System.Drawing.IDeviceContext

The device context in which to draw the text.

text
Type: System.String

The text to draw.

font
Type: System.Drawing.Font

The Font to apply to the drawn text.

pt
Type: System.Drawing.Point

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

foreColor
Type: System.Drawing.Color

The Color to apply to the drawn text.

backColor
Type: System.Drawing.Color

The Color to apply to the background area of the drawn text.

ExceptionCondition
ArgumentNullException

dc is null.

The backColor parameter is applied to the rectangular area containing the drawn text. If font, backcolor or forecolor is null or Color.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.

You can manipulate how the text is drawn by using one of the DrawText overloads that takes a TextFormatFlags parameter.

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.

NoteNote

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 RenderText3 from the form's Paint event handler, passing e as PaintEventArgs.

private void RenderText3(PaintEventArgs e)
{
    TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font,
        new Point(10, 10), Color.Red, Color.PowderBlue);
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.