ערוך

שתף באמצעות


TextRenderer Class

Definition

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

public ref class TextRenderer sealed
public ref class TextRenderer abstract sealed
public sealed class TextRenderer
public static class TextRenderer
type TextRenderer = class
Public NotInheritable Class TextRenderer
Public Class TextRenderer
Inheritance
TextRenderer

Examples

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);
}
Private Sub RenderText1(ByVal e As PaintEventArgs)
    TextRenderer.DrawText(e.Graphics, "Regular Text", _
        Me.Font, New Point(10, 10), SystemColors.ControlText)

End Sub

Remarks

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.

Methods

DrawText(IDeviceContext, ReadOnlySpan<Char>, 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, ReadOnlySpan<Char>, Font, Point, Color, Color)

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

DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Point, Color, TextFormatFlags)

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

DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Point, Color)

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

DrawText(IDeviceContext, ReadOnlySpan<Char>, 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.

DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Rectangle, Color, Color)

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

DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Rectangle, Color, TextFormatFlags)

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

DrawText(IDeviceContext, ReadOnlySpan<Char>, 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, 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, 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, Point, Color)

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

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.

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, Rectangle, Color)

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

MeasureText(IDeviceContext, ReadOnlySpan<Char>, 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.

MeasureText(IDeviceContext, ReadOnlySpan<Char>, 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(IDeviceContext, ReadOnlySpan<Char>, Font)

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

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.

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(IDeviceContext, String, Font)

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

MeasureText(ReadOnlySpan<Char>, 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(ReadOnlySpan<Char>, 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(ReadOnlySpan<Char>, Font)

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

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(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(String, Font)

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

Applies to