StringAlignment Enumeráció

Definíció

A szöveges sztring igazítását adja meg az elrendezési téglalaphoz viszonyítva.

public enum class StringAlignment
public enum StringAlignment
type StringAlignment = 
Public Enum StringAlignment
Öröklődés
StringAlignment

Mezők

Name Érték Description
Near 0

Megadja, hogy a szöveg az elrendezéshez közel legyen igazítva. Balról jobbra elrendezésben a közeli pozíció balra van. A jobbról balra elrendezésben a közeli pozíció jobbra van.

Center 1

Megadja, hogy a szöveg az elrendezési téglalap közepén legyen igazítva.

Far 2

Azt adja meg, hogy a szöveg az elrendezési téglalap forráshelyétől távol legyen igazítva. Balról jobbra elrendezésben a szélső pozíció a jobb. A jobbról balra elrendezésben a szélső pozíció balra van.

Példák

Az alábbi példakód bemutatja, hogyan használható a LineAlignment tulajdonságok és Alignment az enumerálás a StringAlignment sztringek igazításához. Ez a példa Windows Forms használható. Illessze be a kódot egy űrlapba, és hívja meg a ShowLineAndAlignment metódust az űrlap eseményének Paint kezelésekor.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

Megjegyzések

Ha a tulajdonsággal együtt használja, ez az LineAlignment enumerálás beállítja egy rajzolt sztring függőleges igazítását. Ha a Alignment tulajdonsággal együtt használja, ez az enumerálás beállítja a vízszintes igazítást.

A következőre érvényes: