TextRenderer TextRenderer TextRenderer TextRenderer Class

定义

提供用于测量和呈现文本的方法。Provides methods used to measure and render text. 此类不能被继承。This class cannot be inherited.

public ref class TextRenderer sealed
public sealed class TextRenderer
type TextRenderer = class
Public NotInheritable Class TextRenderer
继承
TextRendererTextRendererTextRendererTextRenderer

示例

下面的代码示例演示如何使用 DrawText 方法。The following code example demonstrates how to use the DrawText method. 若要运行此示例, 请将代码粘贴到 Windows 窗体RenderText1中, 并从Paint窗体的事件e处理PaintEventArgs程序调用, 并将作为传递。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


注解

类提供一static组方法, 这些方法可用于在 Windows 窗体控件上测量和绘制文本。 TextRendererThe TextRenderer class provides a set of static methods that can be used for measuring and drawing text on a Windows Form control.

您可以通过使用带有 DrawText 参数的 TextFormatFlags 重载之一,控制文本的绘制方式。You can manipulate how the text is drawn by using one of the DrawText overloads that takes a TextFormatFlags parameter. 例如,TextRenderer 的默认行为是向所绘制文本的边框添加空白以符合延伸标志符号。For example, the default behavior of the TextRenderer is to add padding to the bounding rectangle of the drawn text to accommodate overhanging glyphs. 如果绘制一行文本时不需要这些额外空白,您应当使用带有 DrawTextMeasureText 参数的 SizeTextFormatFlags 版本。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. 有关示例,请参见 MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags)For an example, see MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags).

备注

TextRendererDrawText 方法不支持打印。The DrawText methods of TextRenderer are not supported for printing. 应始终使用DrawString Graphics类的方法。You should always use the DrawString methods of the Graphics class.

方法

DrawText(IDeviceContext, String, Font, Point, Color) DrawText(IDeviceContext, String, Font, Point, Color) DrawText(IDeviceContext, String, Font, Point, Color) 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, Point, Color, Color) DrawText(IDeviceContext, String, Font, Point, Color, Color) DrawText(IDeviceContext, String, Font, Point, Color, 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, Color, TextFormatFlags) DrawText(IDeviceContext, String, Font, Point, Color, Color, TextFormatFlags) DrawText(IDeviceContext, String, Font, Point, Color, Color, TextFormatFlags) 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, TextFormatFlags) DrawText(IDeviceContext, String, Font, Point, Color, TextFormatFlags) DrawText(IDeviceContext, String, Font, Point, Color, TextFormatFlags) 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) DrawText(IDeviceContext, String, Font, Rectangle, Color) DrawText(IDeviceContext, String, Font, Rectangle, 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, Rectangle, Color, Color) DrawText(IDeviceContext, String, Font, Rectangle, Color, Color) DrawText(IDeviceContext, String, Font, Rectangle, Color, Color) 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, Color, TextFormatFlags) DrawText(IDeviceContext, String, Font, Rectangle, Color, Color, TextFormatFlags) DrawText(IDeviceContext, String, Font, Rectangle, Color, Color, TextFormatFlags) 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, TextFormatFlags) DrawText(IDeviceContext, String, Font, Rectangle, Color, TextFormatFlags) DrawText(IDeviceContext, String, Font, Rectangle, Color, TextFormatFlags) 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.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MeasureText(IDeviceContext, String, Font) MeasureText(IDeviceContext, String, Font) MeasureText(IDeviceContext, String, 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(IDeviceContext, String, Font, Size) MeasureText(IDeviceContext, String, Font, Size) MeasureText(IDeviceContext, String, Font, Size) 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, Size, TextFormatFlags) MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags) MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags) 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(String, Font) MeasureText(String, Font) MeasureText(String, Font) MeasureText(String, Font)

在使用指定字体绘制时,提供指定文本的尺寸(以像素为单位)。Provides the size, in pixels, of the specified text when drawn with the specified font.

MeasureText(String, Font, Size) MeasureText(String, Font, Size) MeasureText(String, Font, Size) 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, Size, TextFormatFlags) MeasureText(String, Font, Size, TextFormatFlags) MeasureText(String, Font, Size, TextFormatFlags) 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.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

适用于