共用方式為


StringFormat 建構函式

定義

初始化新的 StringFormat 物件。

多載

StringFormat()

初始化新的 StringFormat 物件。

StringFormat(StringFormat)

從指定的現有 StringFormat 物件,初始化新的 StringFormat 物件。

StringFormat(StringFormatFlags)

使用指定的 StringFormatFlags 列舉,初始化新的 StringFormat 物件。

StringFormat(StringFormatFlags, Int32)

使用指定的 StringFormatFlags 列舉和語言,初始化新的 StringFormat 物件。

StringFormat()

來源:
StringFormat.cs
來源:
StringFormat.cs
來源:
StringFormat.cs

初始化新的 StringFormat 物件。

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

備註

下表顯示 StringFormat 類別執行個體的初始屬性值。

屬性 初始值
FormatFlags 0 (未設定旗標)
HotkeyPrefix None

適用於

StringFormat(StringFormat)

來源:
StringFormat.cs
來源:
StringFormat.cs
來源:
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 Forms 搭配使用。 將程式代碼貼到表單中,並在處理表單的事件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)

來源:
StringFormat.cs
來源:
StringFormat.cs
來源:
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 Forms 搭配使用。 將程式代碼貼到表單中,並在處理表單的事件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)

來源:
StringFormat.cs
來源:
StringFormat.cs
來源:
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

表示文字語言的值。

適用於