System.Windows.Forms.TextRenderer.DrawText Method

Draws the specified text within the specified bounds, 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.Rectangle bounds, 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.
bounds
The System.Drawing.Rectangle that represents the bounds of the text.
foreColor
The System.Drawing.Color to apply to the drawn text.

Remarks

If font or forecolor is null or System.Drawing.Color.Empty, respectively; 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.

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 erload:System.Windows.Forms.TextRenderer.DrawText that takes a System.Windows.Forms.TextFormatFlags parameter type.

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.

Requirements

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