StringAlignment StringAlignment StringAlignment StringAlignment Enum

定義

レイアウト四角形を基準とした文字列の配置を指定します。Specifies the alignment of a text string relative to its layout rectangle.

public enum class StringAlignment
public enum StringAlignment
type StringAlignment = 
Public Enum StringAlignment
継承
StringAlignmentStringAlignmentStringAlignmentStringAlignment

フィールド

Center Center Center Center 1

テキストがレイアウト四角形の中央に配置されるよう指定します。Specifies that text is aligned in the center of the layout rectangle.

Far Far Far Far 2

テキストがレイアウト四角形の元の位置から離れて配置されるよう指定します。Specifies that text is aligned far from the origin position of the layout rectangle. 左から右のレイアウトでは、最も遠い位置は右側です。In a left-to-right layout, the far position is right. 右から左のレイアウトでは、最も遠い位置は左側です。In a right-to-left layout, the far position is left.

Near Near Near Near 0

テキストがレイアウトの近くに配置されるよう指定します。Specifies the text be aligned near the layout. 左から右のレイアウトでは、最も近い位置は左側です。In a left-to-right layout, the near position is left. 右から左のレイアウトでは、最も近い位置は右側です。In a right-to-left layout, the near position is right.

次のコード例は、 LineAlignment AlignmentプロパティとプロパティStringAlignment 、および列挙体を使用して文字列を配置する方法を示しています。The following code example demonstrates how to use the LineAlignment and Alignment properties and the StringAlignment enumeration to align strings. この例は、Windows フォームと共に使用するように設計されています。This example is designed to be used with Windows Forms. フォームにコードを貼り付け、フォームのShowLineAndAlignment Paintイベントを処理するときにメソッドを呼び出しePaintEventArgs 、として渡します。Paste 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

注釈

LineAlignmentプロパティと共に使用する場合、この列挙体は、描画される文字列の垂直方向の配置を設定します。When used with the LineAlignment property, this enumeration sets the vertical alignment for a drawn string. Alignmentプロパティと共に使用する場合、この列挙体は水平方向の配置を設定します。When used with the Alignment property, this enumeration sets the horizontal alignment.

適用対象