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 Form, 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 Form 控制項上測量和繪製文字。 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 的預設行為是將邊框距離加入至已繪製之文字的週框 (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 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 的淺層複本 (Shallow Copy)。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)

適用於