Bagikan melalui


StringAlignment Enum

Definisi

Menentukan perataan string teks relatif terhadap persegi tata letaknya.

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

Bidang

Center 1

Menentukan bahwa teks diratakan di tengah persegi tata letak.

Far 2

Menentukan bahwa teks diratakan jauh dari posisi asal persegi tata letak. Dalam tata letak kiri-ke-kanan, posisi jauh adalah kanan. Dalam tata letak kanan-ke-kiri, posisi jauh dibiarkan.

Near 0

Menentukan teks yang akan diratakan di dekat tata letak. Dalam tata letak kiri-ke-kanan, posisi dekat dibiarkan. Dalam tata letak kanan-ke-kiri, posisi dekat adalah kanan.

Contoh

Contoh kode berikut menunjukkan cara menggunakan LineAlignment properti dan Alignment dan StringAlignment enumerasi untuk menyelaraskan string. Contoh ini dirancang untuk digunakan dengan Formulir Windows. Tempelkan kode ke dalam formulir dan panggil ShowLineAndAlignment metode saat menangani peristiwa formulir Paint , meneruskan e sebagai 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

Keterangan

Saat digunakan dengan LineAlignment properti , enumerasi ini mengatur perataan vertikal untuk string yang digambar. Saat digunakan dengan Alignment properti , enumerasi ini mengatur perataan horizontal.

Berlaku untuk