System.Windows.Forms.TextRenderer.DrawText Method

Draws the specified text at the specified location using the specified device context, font, and color.

Syntax

public static void DrawText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Point pt, System.Drawing.Color foreColor)

Parameters

dc
The device context in which to draw the text.
text
The text to draw.
font
The System.Drawing.Font to apply to the drawn text.
pt
The System.Drawing.Point that represents the upper-left corner of the drawn text.
foreColor
The System.Drawing.Color to apply to the drawn text.

Remarks

You can manipulate how the text is drawn by using one of the TextRenderer.DrawText(System.Drawing.IDeviceContext, string, System.Drawing.Font, System.Drawing.Rectangle, System.Drawing.Color, TextFormatFlags) overloads that takes a System.Windows.Forms.TextFormatFlags parameter.

If font is null or forecolor is System.Drawing.Color.Empty, the TextRenderer.DrawText(System.Drawing.IDeviceContext, string, System.Drawing.Font, System.Drawing.Point, System.Drawing.Color) method will draw the text in the font or color currently selected in the device context specified by dc. If forecolor is System.Drawing.Color.Transparent, the text will not be drawn.

The text rendering offered by the System.Windows.Forms.TextRenderer class is based on GDI text rendering and is not supported for printing from Windows Forms. Instead, use the erload:System.Drawing.Graphics.DrawString methods of the System.Drawing.Graphics class.

Note:

The erload:System.Windows.Forms.TextRenderer.DrawText methods that specify a System.Drawing.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 erload:System.Windows.Forms.TextRenderer.DrawText methods that specify a System.Drawing.Rectangle for the bounds of the drawn text.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0