TextRenderer Class
Provides methods used to measure and render text. This class cannot be inherited.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The TextRenderer type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | DrawText(IDeviceContext, String, Font, Point, Color) | Draws the specified text at the specified location using the specified device context, font, and color. |
![]() ![]() | DrawText(IDeviceContext, String, Font, Rectangle, Color) | Draws the specified text within the specified bounds, using the specified device context, font, and color. |
![]() ![]() | DrawText(IDeviceContext, String, Font, Point, Color, Color) | Draws the specified text at the specified location, using the specified device context, font, color, and back color. |
![]() ![]() | DrawText(IDeviceContext, String, Font, Point, Color, TextFormatFlags) | Draws the specified text at the specified location using the specified device context, font, color, and formatting instructions. |
![]() ![]() | DrawText(IDeviceContext, String, Font, Rectangle, Color, Color) | Draws the specified text within the specified bounds using the specified device context, font, color, and back color. |
![]() ![]() | DrawText(IDeviceContext, String, Font, Rectangle, Color, TextFormatFlags) | Draws the specified text within the specified bounds using the specified device context, font, color, and formatting instructions. |
![]() ![]() | DrawText(IDeviceContext, String, Font, Point, Color, Color, TextFormatFlags) | Draws the specified text at the specified location using the specified device context, font, color, back color, and formatting instructions |
![]() ![]() | DrawText(IDeviceContext, String, Font, Rectangle, Color, Color, TextFormatFlags) | Draws the specified text within the specified bounds using the specified device context, font, color, back color, and formatting instructions. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() | MeasureText(String, Font) | Provides the size, in pixels, of the specified text when drawn with the specified font. |
![]() ![]() | MeasureText(IDeviceContext, String, Font) | Provides the size, in pixels, of the specified text drawn with the specified font in the specified device context. |
![]() ![]() | MeasureText(String, Font, Size) | Provides the size, in pixels, of the specified text when drawn with the specified font, using the specified size to create an initial bounding rectangle. |
![]() ![]() | MeasureText(IDeviceContext, String, Font, Size) | Provides the size, in pixels, of the specified text when drawn with the specified font in the specified device context, using the specified size to create an initial bounding rectangle for the text. |
![]() ![]() | MeasureText(String, Font, Size, TextFormatFlags) | Provides the size, in pixels, of the specified text when drawn with the specified font and formatting instructions, using the specified size to create the initial bounding rectangle for the text. |
![]() ![]() | MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags) | Provides the size, in pixels, of the specified text when drawn with the specified device context, font, and formatting instructions, using the specified size to create the initial bounding rectangle for the text. |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
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.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
