TextFormatFlags 枚举


指定文本字符串的显示和布局信息。Specifies the display and layout information for text strings.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class TextFormatFlags
public enum TextFormatFlags
type TextFormatFlags = 
Public Enum TextFormatFlags


Bottom 8

对齐边框底部的文本。Aligns the text on the bottom of the bounding rectangle. 仅对于单行文本,才可应用此成员。Applied only when the text is a single line.

Default 0

应用默认的格式设置,即左对齐。Applies the default formatting, which is left-aligned.

EndEllipsis 32768

移除修整行的结尾,并以省略号进行替换。Removes the end of trimmed lines, and replaces them with an ellipsis.

ExpandTabs 64

扩展制表符。Expands tab characters. 每个制表符的默认字符数是 8。The default number of characters per tab is eight. WordEllipsisPathEllipsisEndEllipsis 值不能与 ExpandTabs 一起使用。The WordEllipsis, PathEllipsis, and EndEllipsis values cannot be used with ExpandTabs.

ExternalLeading 512

在行高中包括字体外部间隙。Includes the font external leading in line height. 通常,文本的行高度中不包括外部间隙。Typically, external leading is not included in the height of a line of text.

GlyphOverhangPadding 0

在边框中添加空白边距以容纳延伸的标志符号。Adds padding to the bounding rectangle to accommodate overhanging glyphs.

HidePrefix 1048576

没有作用的旧值。A legacy value that has no effect. 它忽略了文本中的 & 前缀字符,这样一来,后面的字母不会带有下划线,但其他助记前缀字符仍会得到处理。It ignored the ampersand (&) prefix character in the text, so that the letter that followed was not underlined, but other mnemonic-prefix characters were still processed.

HorizontalCenter 1

将边框内的文本水平居中对齐。Centers the text horizontally within the bounding rectangle.

Internal 4096

使用系统字体计算文本规格。Uses the system font to calculate text metrics.

Left 0

对齐剪辑区域左侧的文本。Aligns the text on the left side of the clipping area.

LeftAndRightPadding 536870912

在边框的两边添加空白边距。Adds padding to both sides of the bounding rectangle.

ModifyString 65536

不影响绘制的文本。Has no effect on the drawn text.

NoClipping 256

允许显示标志符号的延伸部分和延伸到格式化矩形外的未换行文本。Allows the overhanging parts of glyphs and unwrapped text reaching outside the formatting rectangle to show.

NoFullWidthCharacterBreak 524288

没有作用的旧值。A legacy value that has no effect. 它可防止双倍宽度字符串中出现换行符,这样一来,换行规则会等同于单倍宽度字符串的换行规则。It prevents a line break at a double-wide character string, so that the line-breaking rule is equivalent to that for single-wide character strings.

NoPadding 268435456

不在边框中添加空白边距。Does not add padding to the bounding rectangle.

NoPrefix 2048

关闭对前缀字符的处理。Turns off processing of prefix characters. 通常情况下,& 助记键前缀字符解释为强调后续字符的指令,而 && 助记键前缀字符解释为打印单个 & 的指令。Typically, the ampersand (&) mnemonic-prefix character is interpreted as a directive to underscore the character that follows, and the double-ampersand (&&) mnemonic-prefix characters as a directive to print a single ampersand. 通过指定 NoPrefix,可以关闭此处理。By specifying NoPrefix, this processing is turned off. 例如,应用 NoPrefix 的“A&bc&&d”输入字符串到导致“A&bc&&d”的输出结果。For example, an input string of "A&bc&&d" with NoPrefix applied would result in output of "A&bc&&d". PrefixOnly 进行比较。Compare with PrefixOnly.

PathEllipsis 16384

移除修整行的中心并以省略号进行替换。Removes the center of trimmed lines and replaces it with an ellipsis.

PrefixOnly 2097152

没有作用的旧值。A legacy value that has no effect. 它仅在 & 前缀字符后面的字符位置添加下划线,且不会为字符串中的任何其他字符添加下划线。It drew only an underline at the position of the character following the ampersand (&) prefix character, and did not draw any other characters in the string.

PreserveGraphicsClipping 16777216

保留 Graphics 对象指定的剪辑。Preserves the clipping specified by a Graphics object. 仅适用于接收实际上是一个 IDeviceContextGraphics 的方法。Applies only to methods receiving an IDeviceContext that is a Graphics.

PreserveGraphicsTranslateTransform 33554432

保留 Graphics 指定的转换。Preserves the transformation specified by a Graphics. 仅适用于接收实际上是一个 IDeviceContextGraphics 的方法。Applies only to methods receiving an IDeviceContext that is a Graphics.

Right 2

对齐剪辑区域右侧的文本。Aligns the text on the right side of the clipping area.

RightToLeft 131072

从右向左显示文本。Displays the text from right to left.

SingleLine 32

显示单行文本。Displays the text in a single line.

TextBoxControl 8192

指定应格式化文本以在 TextBox 控件中显示。Specifies the text should be formatted for display on a TextBox control.

Top 0

对齐边框顶部的文本。Aligns the text on the top of the bounding rectangle.

VerticalCenter 4

在边框内部垂直居中对齐文本。Centers the text vertically, within the bounding rectangle.

WordBreak 16

在单词的结尾处断开文本。Breaks the text at the end of a word.

WordEllipsis 262144

将行修整到最近的单词处,并在修整行的结尾处放置省略号。Trims the line to the nearest word and an ellipsis is placed at the end of a trimmed line.


下面的示例演示如何使用TextFormatFlags枚举。The following example demonstrates how to use the TextFormatFlags enumeration. 若要运行此示例, 请将以下代码粘贴到 Windows 窗体中。To run this example, paste the following code into a Windows Form. RenderText6窗体的Paint事件处理程序调用, e传递PaintEventArgs为。Call RenderText6 from the form's Paint event handler, passing e as PaintEventArgs.

private void RenderText6(PaintEventArgs e)
    TextFormatFlags flags = TextFormatFlags.Bottom | TextFormatFlags.EndEllipsis;
    TextRenderer.DrawText(e.Graphics, "This is some text that will be clipped at the end.", this.Font,
        new Rectangle(10, 10, 100, 50), SystemColors.ControlText, flags);
Private Sub RenderText6(ByVal e As PaintEventArgs)
    Dim flags As TextFormatFlags = TextFormatFlags.Bottom Or _
    TextRenderer.DrawText(e.Graphics, _
    "This is some text that will be clipped at the end.", _
    Me.Font, New Rectangle(10, 10, 100, 50), SystemColors.ControlText, flags)

End Sub


绘制和测量文本TextRenderer时, 将使用枚举。TextFormatFlagsThe TextFormatFlags enumeration is used by the TextRenderer when drawing and measuring text. 虽然您可以ExpandTabs使用标志展开现有制表位, 但不支持向绘制文本添加制表位。 TextRendererThe TextRenderer does not support adding tab stops to drawn text, although you can expand existing tab stops using the ExpandTabs flag.