This documentation is archived and is not being maintained.

StringFormatFlags Enumeration

Specifies the display and layout information for text strings.

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

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

public enum class StringFormatFlags
/** @attribute FlagsAttribute() */ 
public enum StringFormatFlags
public enum StringFormatFlags

 Member nameDescription
DirectionRightToLeftText is displayed from right to left. 
DirectionVerticalText is vertically aligned. 
DisplayFormatControlControl characters such as the left-to-right mark are shown in the output with a representative glyph. 
FitBlackBoxParts of characters are allowed to overhang the string's layout rectangle. By default, characters are repositioned to avoid any overhang. 
LineLimitOnly entire lines are laid out in the formatting rectangle. By default layout continues until the end of the text, or until no more lines are visible as a result of clipping, whichever comes first. Note that the default settings allow the last line to be partially obscured by a formatting rectangle that is not a whole multiple of the line height. To ensure that only whole lines are seen, specify this value and be careful to provide a formatting rectangle at least as tall as the height of one line. 
MeasureTrailingSpacesIncludes the trailing space at the end of each line. By default the boundary rectangle returned by the MeasureString method excludes the space at the end of each line. Set this flag to include that space in measurement. 
Supported by the .NET Compact FrameworkNoClipOverhanging parts of glyphs, and unwrapped text reaching outside the formatting rectangle are allowed to show. By default all text and glyph parts reaching outside the formatting rectangle are clipped. 
NoFontFallbackFallback to alternate fonts for characters not supported in the requested font is disabled. Any missing characters are displayed with the fonts missing glyph, usually an open square. 
Supported by the .NET Compact FrameworkNoWrapText wrapping between lines when formatting within a rectangle is disabled. This flag is implied when a point is passed instead of a rectangle, or when the specified rectangle has a zero line length. 

StringFormatFlags is used by the StringFormat class.


The FitBlackBox field was misnamed and its behavior is similar to the NoFitBlackBox field in the original GDI+ implementation.

The following code example demonstrates the following members:

This example is designed to be used with Windows Forms. Paste the code into a form and call the ShowLineAndAlignment method when handling the form's Paint event, passing e as PaintEventArgs.

   void ShowLineAndAlignment( PaintEventArgs^ e )
      // Construct a new Rectangle .
      Rectangle displayRectangle = Rectangle(Point(40,40),System::Drawing::Size( 80, 80 ));
      // Construct 2 new StringFormat objects
      StringFormat^ format1 = gcnew StringFormat( StringFormatFlags::NoClip );
      StringFormat^ format2 = gcnew StringFormat( format1 );
      // Set the LineAlignment and Alignment properties for
      // both StringFormat objects to different values.
      format1->LineAlignment = StringAlignment::Near;
      format1->Alignment = StringAlignment::Center;
      format2->LineAlignment = StringAlignment::Center;
      format2->Alignment = StringAlignment::Far;
      // Draw the bounding rectangle and a string for each
      // StringFormat object.
      e->Graphics->DrawRectangle( Pens::Black, displayRectangle );
      e->Graphics->DrawString( "Showing Format1", this->Font, Brushes::Red, displayRectangle, format1 );
      e->Graphics->DrawString( "Showing Format2", this->Font, Brushes::Red, displayRectangle, format2 );

private void ShowLineAndAlignment(PaintEventArgs e)
    // Construct a new Rectangle .
    Rectangle displayRectangle = new Rectangle(new Point(40, 40),
                                new Size(80, 80));

    // Construct 2 new StringFormat objects
    StringFormat format1 = new StringFormat(StringFormatFlags.NoClip);
    StringFormat format2 = new StringFormat(format1);

    // Set the LineAlignment and Alignment properties for
    // both StringFormat objects to different values.

    // Draw the bounding rectangle and a string for each
    // StringFormat object.
    e.get_Graphics().DrawRectangle(Pens.get_Black(), displayRectangle);
    e.get_Graphics().DrawString("Showing Format1", this.get_Font(), 
        Brushes.get_Red(), (RectangleF.op_Implicit((displayRectangle))),
    e.get_Graphics().DrawString("Showing Format2", this.get_Font(),
        Brushes.get_Red(), RectangleF.op_Implicit((displayRectangle)),
} //ShowLineAndAlignment

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0