StringFormatFlags 枚举

指定文本字符串的显示和布局信息。

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

**命名空间:**System.Drawing
**程序集:**System.Drawing(在 system.drawing.dll 中)

语法

声明
<FlagsAttribute> _
Public Enumeration StringFormatFlags
用法
Dim instance As StringFormatFlags
[FlagsAttribute] 
public enum StringFormatFlags
[FlagsAttribute] 
public enum class StringFormatFlags
/** @attribute FlagsAttribute() */ 
public enum StringFormatFlags
FlagsAttribute 
public enum StringFormatFlags

成员

  成员名称 说明
DirectionRightToLeft 按从右向左的顺序显示文本。 
DirectionVertical 文本垂直对齐。 
DisplayFormatControl 控制字符(如从左到右标记)随具有代表性的标志符号一起显示在输出中。 
FitBlackBox 允许部分字符延伸该字符串的布局矩形。默认情况下,将重新定位字符以避免任何延伸。 
LineLimit 在格式化的矩形中只布置整行。默认情况下,这种布置要继续到文本的结尾为止,或者到由于剪辑而不再有可见的行为止,看哪一种情况先发生。注意,此默认设置允许不是行高整数倍的格式化矩形将最后一行部分地遮住。若要确保看到的都是整行,请指定此值,并仔细地提供格式化矩形,使其高度至少为一个行高。 
MeasureTrailingSpaces 包括每一行结尾处的尾随空格。在默认情况下,MeasureString 方法返回的边框都将排除每一行结尾处的空格。设置此标记以便在测定时将空格包括进去。 
由 .NET Compact Framework 支持 NoClip 允许显示标志符号的伸出部分和延伸到边框外的未换行文本。在默认情况下,延伸到边框外侧的所有文本和标志符号部分都被剪裁。 
NoFontFallback 对于请求的字体中不支持的字符,禁用回退到可选字体。缺失的任何字符都用缺失标志符号的字体显示,通常是一个空的方块。 
由 .NET Compact Framework 支持 NoWrap 在矩形内设置格式时,禁用文本换行功能。当传递的是点而不是矩形时,或者指定的矩形行长为零时,已隐含此标记。 

备注

StringFormatFlagsStringFormat 类使用。

提示

FitBlackBox 字段被错误命名,它的行为与原始 GDI+ 实现中 NoFitBlackBox 字段的行为类似。

示例

下面的代码示例演示以下成员:

此示例是针对使用 Windows 窗体而设计的。将代码粘贴到一个窗体中,然后在处理窗体的 Paint 事件时调用 ShowLineAndAlignment 方法,并传递 e 作为 PaintEventArgs

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
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:
   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.set_LineAlignment(StringAlignment.Near);
    format1.set_Alignment(StringAlignment.Center);
    format2.set_LineAlignment(StringAlignment.Center);
    format2.set_Alignment(StringAlignment.Far);

    // 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))),
        format1);
    e.get_Graphics().DrawString("Showing Format2", this.get_Font(),
        Brushes.get_Red(), RectangleF.op_Implicit((displayRectangle)),
        format2);
} //ShowLineAndAlignment

平台

Windows 98、Windows 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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

System.Drawing 命名空间