Freigeben über


StringAlignment Enumeration

Definition

Gibt die Ausrichtung einer Textzeichenfolge relativ zum Layoutrechteck an.

public enum class StringAlignment
public enum StringAlignment
type StringAlignment = 
Public Enum StringAlignment
Vererbung
StringAlignment

Felder

Name Wert Beschreibung
Near 0

Gibt den Text an, der in der Nähe des Layouts ausgerichtet werden soll. In einem Links-nach-rechts-Layout ist die nahe Position links. In einem Layout von rechts nach links ist die nahe Position rechts.

Center 1

Gibt an, dass Text in der Mitte des Layoutrechtecks ausgerichtet ist.

Far 2

Gibt an, dass Der Text weit von der Ursprungsposition des Layoutrechtecks entfernt ausgerichtet wird. In einem Links-nach-rechts-Layout ist die weit entfernte Position rechts. In einem Layout von rechts nach links befindet sich die weit entfernte Position links.

Beispiele

Im folgenden Codebeispiel wird die Verwendung der LineAlignment Eigenschaften und Alignment der StringAlignment Enumeration zum Ausrichten von Zeichenfolgen veranschaulicht. Dieses Beispiel wurde für die Verwendung mit Windows Forms entwickelt. Fügen Sie den Code in ein Formular ein, und rufen Sie die ShowLineAndAlignment Methode beim Behandeln des Formularereignisses Paint auf und übergeben als 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

Hinweise

Bei Verwendung mit der LineAlignment Eigenschaft legt diese Enumeration die vertikale Ausrichtung für eine gezeichnete Zeichenfolge fest. Bei Verwendung mit der Alignment Eigenschaft legt diese Enumeration die horizontale Ausrichtung fest.

Gilt für: