TextFormatFlags TextFormatFlags TextFormatFlags TextFormatFlags Enum


Specifies the display and layout information for text strings.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

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


Bottom Bottom Bottom Bottom 8

Aligns the text on the bottom of the bounding rectangle. Applied only when the text is a single line.

Default Default Default Default 0

Applies the default formatting, which is left-aligned.

EndEllipsis EndEllipsis EndEllipsis EndEllipsis 32768

Removes the end of trimmed lines, and replaces them with an ellipsis.

ExpandTabs ExpandTabs ExpandTabs ExpandTabs 64

Expands tab characters. The default number of characters per tab is eight. The WordEllipsis, PathEllipsis, and EndEllipsis values cannot be used with ExpandTabs.

ExternalLeading ExternalLeading ExternalLeading 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 GlyphOverhangPadding GlyphOverhangPadding GlyphOverhangPadding 0

Adds padding to the bounding rectangle to accommodate overhanging glyphs.

HidePrefix HidePrefix HidePrefix 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 HorizontalCenter HorizontalCenter HorizontalCenter 1

Centers the text horizontally within the bounding rectangle.

Internal Internal Internal Internal 4096

Uses the system font to calculate text metrics.

Left Left Left Left 0

Aligns the text on the left side of the clipping area.

LeftAndRightPadding LeftAndRightPadding LeftAndRightPadding LeftAndRightPadding 536870912

Adds padding to both sides of the bounding rectangle.

ModifyString ModifyString ModifyString ModifyString 65536

Has no effect on the drawn text.

NoClipping NoClipping NoClipping NoClipping 256

Allows the overhanging parts of glyphs and unwrapped text reaching outside the formatting rectangle to show.

NoFullWidthCharacterBreak NoFullWidthCharacterBreak NoFullWidthCharacterBreak 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 NoPadding NoPadding NoPadding 268435456

Does not add padding to the bounding rectangle.

NoPrefix NoPrefix NoPrefix 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. By specifying NoPrefix, this processing is turned off. For example, an input string of "A&bc&&d" with NoPrefix applied would result in output of "A&bc&&d". Compare with PrefixOnly.

PathEllipsis PathEllipsis PathEllipsis PathEllipsis 16384

Removes the center of trimmed lines and replaces it with an ellipsis.

PrefixOnly PrefixOnly PrefixOnly 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 PreserveGraphicsClipping PreserveGraphicsClipping PreserveGraphicsClipping 16777216

Preserves the clipping specified by a Graphics object. Applies only to methods receiving an IDeviceContext that is a Graphics.

PreserveGraphicsTranslateTransform PreserveGraphicsTranslateTransform PreserveGraphicsTranslateTransform PreserveGraphicsTranslateTransform 33554432

Preserves the transformation specified by a Graphics. Applies only to methods receiving an IDeviceContext that is a Graphics.

Right Right Right Right 2

Aligns the text on the right side of the clipping area.

RightToLeft RightToLeft RightToLeft RightToLeft 131072

Displays the text from right to left.

SingleLine SingleLine SingleLine SingleLine 32

Displays the text in a single line.

TextBoxControl TextBoxControl TextBoxControl TextBoxControl 8192

Specifies the text should be formatted for display on a TextBox control.

Top Top Top Top 0

Aligns the text on the top of the bounding rectangle.

VerticalCenter VerticalCenter VerticalCenter VerticalCenter 4

Centers the text vertically, within the bounding rectangle.

WordBreak WordBreak WordBreak WordBreak 16

Breaks the text at the end of a word.

WordEllipsis WordEllipsis WordEllipsis WordEllipsis 262144

Trims the line to the nearest word and an ellipsis is placed at the end of a trimmed line.


The following example demonstrates how to use the ExpandTabs enumeration. To run this example, paste the following code into a Windows Form. 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


The TextFormatFlags enumeration is used by the TextRenderer when drawing and measuring text. The TextRenderer does not support adding tab stops to drawn text, although you can expand existing tab stops using the ExpandTabs flag.

Applies to

See also