Export (0) Print
Expand All

TextRenderer Class

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

System.Object
  System.Windows.Forms.TextRenderer

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public sealed class TextRenderer

The TextRenderer type exposes the following members.

  NameDescription
Public methodStatic memberDrawText(IDeviceContext, String, Font, Point, Color)Draws the specified text at the specified location using the specified device context, font, and color.
Public methodStatic memberDrawText(IDeviceContext, String, Font, Rectangle, Color)Draws the specified text within the specified bounds, using the specified device context, font, and color.
Public methodStatic memberDrawText(IDeviceContext, String, Font, Point, Color, Color)Draws the specified text at the specified location, using the specified device context, font, color, and back color.
Public methodStatic memberDrawText(IDeviceContext, String, Font, Point, Color, TextFormatFlags)Draws the specified text at the specified location using the specified device context, font, color, and formatting instructions.
Public methodStatic memberDrawText(IDeviceContext, String, Font, Rectangle, Color, Color)Draws the specified text within the specified bounds using the specified device context, font, color, and back color.
Public methodStatic memberDrawText(IDeviceContext, String, Font, Rectangle, Color, TextFormatFlags)Draws the specified text within the specified bounds using the specified device context, font, color, and formatting instructions.
Public methodStatic memberDrawText(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
Public methodStatic memberDrawText(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.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberMeasureText(String, Font)Provides the size, in pixels, of the specified text when drawn with the specified font.
Public methodStatic memberMeasureText(IDeviceContext, String, Font)Provides the size, in pixels, of the specified text drawn with the specified font in the specified device context.
Public methodStatic memberMeasureText(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.
Public methodStatic memberMeasureText(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.
Public methodStatic memberMeasureText(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.
Public methodStatic memberMeasureText(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.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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).

NoteNote

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 void RenderText1(PaintEventArgs e)
{
    TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font, 
        new Point(10, 10), SystemColors.ControlText);

}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft