TextRenderer 類別

定義

提供方法用來測量及呈現文字。Provides methods used to measure and render text. 此類別無法獲得繼承。This class cannot be inherited.

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

範例

下列程式碼範例會示範如何使用 DrawText 方法。The following code example demonstrates how to use the DrawText method. 若要執行這個範例,請將程式碼貼到 Windows Form 中,然後 RenderText1 從表單的 Paint 事件處理常式呼叫,傳遞 ePaintEventArgsTo 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


備註

TextRenderer類別提供一組 static 方法,可用來測量和繪製 Windows Form 控制項上的文字。The 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 的預設行為是將邊框距離加入至已繪製之文字的週框 (Bounding Rectangle),以容納突出 (Overhanging) 的圖像 (Glyph)。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 類別的方法 GraphicsYou should always use the DrawString methods of the Graphics class.

方法

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, 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, 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, TextFormatFlags)

使用指定的裝置內容、字型、色彩和格式化指示,在指定的位置上繪製指定的文字。Draws the specified text at the specified location 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, 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, 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, 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)

使用指定的裝置內容、字型和色彩,在指定的位置上繪製指定的文字。Draws the specified text at the specified location 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, 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)

使用指定的裝置內容、字型、色彩和格式化指示,在指定的位置上繪製指定的文字。Draws the specified text at the specified location 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.

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)

使用指定的裝置內容、字型、色彩、背景色彩和格式化指示,在指定的界限之內繪製指定的文字。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)

使用指定的裝置內容、字型、色彩和格式化指示,在指定的界限之內繪製指定的文字。Draws the specified text within the specified bounds using the specified device context, font, color, and formatting instructions.

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

提供在指定的裝置內容中以指定的字型繪製之文字的大小 (以像素為單位)。Provides the size, in pixels, of the specified text drawn with the specified font in the specified device context.

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)

使用指定的大小建立文字的初始周框 ,以指定的裝置內容、字型和格式化指示繪製時,提供所指定文字的大小 (以像素為單位)。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(ReadOnlySpan<Char>, Font)

以指定的字型繪製時,提供所指定文字的大小 (以像素為單位)。Provides the size, in pixels, of the specified text when drawn with the specified font.

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

以指定的字型繪製時,提供所指定文字的大小 (以像素為單位)。Provides the size, in pixels, of the specified text when drawn with the specified font.

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)

使用指定的大小建立文字的初始周框 ,以指定的字型和格式化指示繪製時,提供所指定文字的大小 (以像素為單位)。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.

適用於