TextRenderer Class

 

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)

System.Object
  System.Windows.Forms.TextRenderer

public sealed class TextRenderer

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext, String, Font, Point, Color)

Draws the specified text at the specified location using the specified device context, font, and color.

System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext, String, Font, Point, Color, Color)

Draws the specified text at the specified location, using the specified device context, font, color, and back color.

System_CAPS_pubmethodSystem_CAPS_staticDrawText(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

System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext, String, Font, Point, Color, TextFormatFlags)

Draws the specified text at the specified location using the specified device context, font, color, and formatting instructions.

System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext, String, Font, Rectangle, Color)

Draws the specified text within the specified bounds, using the specified device context, font, and color.

System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext, String, Font, Rectangle, Color, Color)

Draws the specified text within the specified bounds using the specified device context, font, color, and back color.

System_CAPS_pubmethodSystem_CAPS_staticDrawText(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.

System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext, String, Font, Rectangle, Color, TextFormatFlags)

Draws the specified text within the specified bounds using the specified device context, font, color, and formatting instructions.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_staticMeasureText(IDeviceContext, String, Font)

Provides the size, in pixels, of the specified text drawn with the specified font in the specified device context.

System_CAPS_pubmethodSystem_CAPS_staticMeasureText(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.

System_CAPS_pubmethodSystem_CAPS_staticMeasureText(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.

System_CAPS_pubmethodSystem_CAPS_staticMeasureText(String, Font)

Provides the size, in pixels, of the specified text when drawn with the specified font.

System_CAPS_pubmethodSystem_CAPS_staticMeasureText(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.

System_CAPS_pubmethodSystem_CAPS_staticMeasureText(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.

System_CAPS_pubmethodToString()

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

System_CAPS_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
Available since 2.0

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

Return to top
Show: