StringFormatFlags StringFormatFlags StringFormatFlags StringFormatFlags Enum

定义

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

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

public enum class StringFormatFlags
[System.Flags]
public enum StringFormatFlags
type StringFormatFlags = 
Public Enum StringFormatFlags
继承
StringFormatFlagsStringFormatFlagsStringFormatFlagsStringFormatFlags
属性

字段

DirectionRightToLeft DirectionRightToLeft DirectionRightToLeft DirectionRightToLeft 1

按从右向左的顺序显示文本。Text is displayed from right to left.

DirectionVertical DirectionVertical DirectionVertical DirectionVertical 2

垂直对齐文本。Text is vertically aligned.

DisplayFormatControl DisplayFormatControl DisplayFormatControl DisplayFormatControl 32

控制字符(如从左到右标记)随具有代表性的字形一起显示在输出中。Control characters such as the left-to-right mark are shown in the output with a representative glyph.

FitBlackBox FitBlackBox FitBlackBox FitBlackBox 4

允许部分字符延伸该字符串的布局矩形。Parts of characters are allowed to overhang the string's layout rectangle. 默认情况下,将重新定位字符以避免任何延伸。By default, characters are repositioned to avoid any overhang.

LineLimit LineLimit LineLimit LineLimit 8192

在格式化的矩形中只布置整行。Only 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.

MeasureTrailingSpaces MeasureTrailingSpaces MeasureTrailingSpaces MeasureTrailingSpaces 2048

包括每一行结尾处的尾随空格。Includes the trailing space at the end of each line. 在默认情况下,MeasureString 方法返回的边界矩形都将排除每一行结尾处的空格。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.

NoClip NoClip NoClip NoClip 16384

允许显示字形符号的伸出部分和延伸到矩形外的未换行文本。Overhanging 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.

NoFontFallback NoFontFallback NoFontFallback NoFontFallback 1024

对于请求的字体中不支持的字符,禁用回退到可选字体。Fallback 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.

NoWrap NoWrap NoWrap NoWrap 4096

在矩形内设置格式时,禁用自动换行功能。Text 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.

示例

下面的代码示例演示了以下成员:The following code example demonstrates the following members:

此示例旨在与 Windows 窗体一起使用。This example is designed to be used with Windows Forms. 将代码粘贴到窗体并调用ShowLineAndAlignment方法时处理该窗体Paint事件,并传递e作为PaintEventArgsPaste the code into a form and call the ShowLineAndAlignment method when handling the form's Paint event, passing e as PaintEventArgs.

private:
   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.
    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, (RectangleF)displayRectangle, format1);
    e.Graphics.DrawString("Showing Format2", this.Font, 
        Brushes.Red, (RectangleF)displayRectangle, format2);
}
Private Sub ShowLineAndAlignment(ByVal e As PaintEventArgs)

    ' Construct a new Rectangle.
    Dim displayRectangle _
        As New Rectangle(New Point(40, 40), New Size(80, 80))

    ' Construct two new StringFormat objects
    Dim format1 As New StringFormat(StringFormatFlags.NoClip)
    Dim format2 As New 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", Me.Font, Brushes.Red, _
        RectangleF.op_Implicit(displayRectangle), format1)
    e.Graphics.DrawString("Showing Format2", Me.Font, Brushes.Red, _
        RectangleF.op_Implicit(displayRectangle), format2)
End Sub

注解

StringFormatFlagsStringFormat类。StringFormatFlags is used by the StringFormat class.

备注

FitBlackBox 字段已名不符实了,其行为类似于NoFitBlackBox字段中的原始的 GDI + 实现。The FitBlackBox field was misnamed and its behavior is similar to the NoFitBlackBox field in the original GDI+ implementation.

适用于