Freigeben über


StringAlignment-Enumeration

Gibt die Ausrichtung einer Textzeichenfolge relativ zum zugehörigen Layoutrechteck an.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

Syntax

'Declaration
Public Enumeration StringAlignment
'Usage
Dim instance As StringAlignment
public enum StringAlignment
public enum class StringAlignment
public enum StringAlignment
public enum StringAlignment

Member

  Membername Beschreibung
Unterstützt von .NET Compact Framework Center Gibt an, dass der Text in der Mitte des Layoutrechtecks ausgerichtet ist. 
Unterstützt von .NET Compact Framework Far Gibt an, dass der Text weit entfernt von der Ursprungsposition des Layoutrechtecks ausgerichtet ist. Bei einem Layout mit Ausrichtung von links nach rechts ist die weit entfernte Position rechts. Bei einem Layout mit Ausrichtung von rechts nach links ist die weit entfernte Position links. 
Unterstützt von .NET Compact Framework Near Gibt an, dass der Text nah am Layout ausgerichtet wird. Bei einem Layout mit Ausrichtung von links nach rechts ist die nah ausgerichtete Position links. Bei einem Layout mit Ausrichtung von rechts nach links ist die nah ausgerichtete Position rechts. 

Hinweise

Bei Verwendung mit der LineAlignment-Eigenschaft legt diese Enumeration die vertikale Ausrichtung für eine gezeichnete Zeichenfolge fest. Wenn sie mit der Alignment-Eigenschaft verwendet wird, legt diese Enumeration die horizontale Ausrichtung fest.

Beispiel

Im folgenden Codebeispiel wird die Verwendung der LineAlignment-Eigenschaft und der Alignment-Eigenschaft sowie der StringAlignment-Enumeration veranschaulicht. Dieses Beispiel ist für die Verwendung mit Windows Forms vorgesehen. Fügen Sie den Code in ein Formular ein, und rufen Sie beim Behandeln des Paint-Ereignisses des Formulars die ShowLineAndAlignment-Methode auf, wobei Sie e als PaintEventArgs übergeben.

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

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0

Siehe auch

Referenz

System.Drawing-Namespace