StringFormat 构造函数

定义

初始化新的 StringFormat 对象。

重载

StringFormat()

初始化新的 StringFormat 对象。

StringFormat(StringFormat)

从指定的现有 StringFormat 对象初始化新 StringFormat 对象。

StringFormat(StringFormatFlags)

用指定的 StringFormatFlags 枚举初始化新 StringFormat 对象。

StringFormat(StringFormatFlags, Int32)

用指定的 StringFormatFlags 枚举和语言初始化新的 StringFormat 对象。

StringFormat()

Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs

初始化新的 StringFormat 对象。

public:
 StringFormat();
public StringFormat ();
Public Sub New ()

注解

下表显示 StringFormat 类的实例的初始属性值。

属性 初始值
FormatFlags 0 (未设置任何标志)
HotkeyPrefix None

适用于

StringFormat(StringFormat)

Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs

从指定的现有 StringFormat 对象初始化新 StringFormat 对象。

public:
 StringFormat(System::Drawing::StringFormat ^ format);
public StringFormat (System.Drawing.StringFormat format);
new System.Drawing.StringFormat : System.Drawing.StringFormat -> System.Drawing.StringFormat
Public Sub New (format As StringFormat)

参数

format
StringFormat

StringFormat 对象,从该对象初始化新 StringFormat 对象。

例外

formatnull

示例

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

此示例旨在与 Windows 窗体 一起使用。 将代码粘贴到窗体中,并在处理窗体的 Paint 事件时调用 ShowLineAndAlignment 方法,作为 ePaintEventArgs传递。

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

适用于

StringFormat(StringFormatFlags)

Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs

用指定的 StringFormatFlags 枚举初始化新 StringFormat 对象。

public:
 StringFormat(System::Drawing::StringFormatFlags options);
public StringFormat (System.Drawing.StringFormatFlags options);
new System.Drawing.StringFormat : System.Drawing.StringFormatFlags -> System.Drawing.StringFormat
Public Sub New (options As StringFormatFlags)

参数

options
StringFormatFlags

StringFormat 对象的 StringFormatFlags 枚举。

示例

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

此示例旨在与 Windows 窗体 一起使用。 将代码粘贴到窗体中,并在处理窗体的 Paint 事件时调用 ShowLineAndAlignment 方法,作为 ePaintEventArgs传递。

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

适用于

StringFormat(StringFormatFlags, Int32)

Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs

用指定的 StringFormatFlags 枚举和语言初始化新的 StringFormat 对象。

public:
 StringFormat(System::Drawing::StringFormatFlags options, int language);
public StringFormat (System.Drawing.StringFormatFlags options, int language);
new System.Drawing.StringFormat : System.Drawing.StringFormatFlags * int -> System.Drawing.StringFormat
Public Sub New (options As StringFormatFlags, language As Integer)

参数

options
StringFormatFlags

StringFormat 对象的 StringFormatFlags 枚举。

language
Int32

一个指示文本语言的值。

适用于