Note: This class is new in the .NET Framework version 2.0.
Provides methods used to measure and render text. This class cannot be inherited.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Visual Basic (Declaration)
Public NotInheritable Class TextRenderer
Dim instance As TextRenderer
public sealed class TextRenderer
public ref class TextRenderer sealed
public final class TextRenderer
public final class TextRenderer
The 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 DrawText overloads that takes a TextFormatFlags parameter. For example, the default behavior of the 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 DrawText and MeasureText that take a Size and TextFormatFlags parameter. For an example, see MeasureText(IDeviceContext,String,Font,Size,TextFormatFlags).
Note |
|---|
| The DrawText methods of TextRenderer are not supported for printing. You should always 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 Sub RenderText1(ByVal e As PaintEventArgs)
TextRenderer.DrawText(e.Graphics, "Regular Text", _
Me.Font, New Point(10, 10), SystemColors.ControlText)
End Sub
private void RenderText1(PaintEventArgs e)
{
TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font,
new Point(10, 10), SystemColors.ControlText);
}
System.Object
System.Windows.Forms.TextRenderer
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
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