HorizontalAlignment Wyliczenie

Definicja

Określa, jak obiekt lub tekst w kontrolce jest wyrównany w poziomie względem elementu kontrolki.

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

Pola

Center 2

Obiekt lub tekst jest wyrównany w środku elementu kontrolki.

Left 0

Obiekt lub tekst jest wyrównany po lewej stronie elementu kontrolki.

Right 1

Obiekt lub tekst jest wyrównany po prawej stronie elementu kontrolki.

Przykłady

W tym przykładzie pokazano, jak za pomocą HorizontalAlignment wyliczenia wyrównać tekst do lewej, prawej lub w środku elementu kontrolki. Najpierw utwórz element TextBox o określonym rozmiarze i dodaj do niego ciąg tekstowy. Następnie użyj elementu członkowskiego Center wyliczenia, aby wyrównać tekst w środku elementu TextBox. W przykładzie założono, że utworzono Form nazwę Form1 i TextBox nazwę textBox1.

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

Uwagi

Ta wyliczenie jest używana w wielu klasach. Częściowa lista tych klas to CheckedListBox, , ColumnHeader, ComboBoxListBoxLabelControlControlPaint, RichTextBoxi .TextBox

Dotyczy