HorizontalAlignment Enum

Definisi

Menentukan bagaimana objek atau teks dalam kontrol diratakan secara horizontal relatif terhadap elemen kontrol.

public enum class HorizontalAlignment
[System.Runtime.InteropServices.ComVisible(true)]
public enum HorizontalAlignment
[<System.Runtime.InteropServices.ComVisible(true)>]
type HorizontalAlignment = 
Public Enum HorizontalAlignment
Warisan
HorizontalAlignment
Atribut

Bidang

Nama Nilai Deskripsi
Left 0

Objek atau teks diratakan di sebelah kiri elemen kontrol.

Right 1

Objek atau teks diratakan di sebelah kanan elemen kontrol.

Center 2

Objek atau teks diratakan di tengah elemen kontrol.

Contoh

Contoh ini menunjukkan cara menggunakan HorizontalAlignment enumerasi untuk meratakan teks ke kiri, kanan, atau di tengah elemen kontrol. Pertama, buat TextBox dengan ukuran tertentu, dan tambahkan string teks ke dalamnya. Kemudian, gunakan anggota Center enumerasi untuk meratakan teks di tengah TextBox. Contoh mengasumsikan bahwa Anda telah membuat Form bernama Form1 dan bernama textBox1TextBox .

private:
   void Form1_Load( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Add a text String* to the TextBox.
      textBox1->Text = "Hello World!";

      // Set the size of the TextBox.
      textBox1->AutoSize = false;
      textBox1->Size = System::Drawing::Size( Width, Height / 3 );

      // Align the text in the center of the control element.
      textBox1->TextAlign = HorizontalAlignment::Center;
   }
private void Form1_Load(object sender, System.EventArgs e)
{
    // Add a text string to the TextBox.
    textBox1.Text = "Hello World!";
    
    // Set the size of the TextBox.
    textBox1.AutoSize = false;
    textBox1.Size = new Size(Width, Height/3);
    
    // Align the text in the center of the control element. 
    textBox1.TextAlign = HorizontalAlignment.Center;							
}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ' Add a text string to the TextBox.
    TextBox1.Text = "Hello World!"

    ' Set the size of the TextBox.
    TextBox1.AutoSize = False
    TextBox1.Size = New Size(Width, Height/3)

    ' Align the text in the center of the control element. 
    TextBox1.TextAlign = HorizontalAlignment.Center
End Sub

Keterangan

Enumerasi ini digunakan dalam berbagai kelas. Daftar parsial kelas-kelas ini adalah CheckedListBox, , ColumnHeader, ComboBox, LabelControlPaint, ListBox, Control, RichTextBox, dan TextBox.

Berlaku untuk