System.Windows.Forms.TextRenderer Class

Provides methods used to measure and render text. This class cannot be inherited.

See Also: TextRenderer Members


public sealed class TextRenderer


The System.Windows.Forms.TextRenderer class provides a set of static methods that can be used for measuring and drawing text on a Windows Form control.

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. For example, the default behavior of the System.Windows.Forms.TextRenderer is to add padding to the bounding rectangle of the drawn text to accommodate overhanging glyphs. If you need to draw a line of text without these extra spaces you should use the versions of TextRenderer.DrawText(System.Drawing.IDeviceContext, string, System.Drawing.Font, System.Drawing.Point, System.Drawing.Color) and TextRenderer.MeasureText(System.Drawing.IDeviceContext, string, System.Drawing.Font) that take a System.Drawing.Size and System.Windows.Forms.TextFormatFlags parameter. For an example, see TextRenderer.MeasureText(System.Drawing.IDeviceContext, string, System.Drawing.Font, System.Drawing.Size, TextFormatFlags).


The erload:System.Windows.Forms.TextRenderer.DrawText methods of System.Windows.Forms.TextRenderer are not supported for printing. You should always use the erload:System.Drawing.Graphics.DrawString methods of the System.Drawing.Graphics class.


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