HorizontalAlignment 列舉

定義

指定控制項中的物件或文字如何水平對齊於相關的控制項項目。Specifies how an object or text in a control is horizontally aligned relative to an element of the control.

public enum class HorizontalAlignment
public enum HorizontalAlignment
[System.Runtime.InteropServices.ComVisible(true)]
public enum HorizontalAlignment
type HorizontalAlignment = 
Public Enum HorizontalAlignment
繼承
HorizontalAlignment
屬性

欄位

Center 2

物件或文字置中對齊控制項項目。The object or text is aligned in the center of the control element.

Left 0

物件或文字靠左對齊控制項項目。The object or text is aligned on the left of the control element.

Right 1

物件或文字靠右對齊控制項項目。The object or text is aligned on the right of the control element.

範例

這個範例示範如何使用 HorizontalAlignment 列舉,將文字對齊控制項專案的左邊、右邊或中央。This example shows how to use the HorizontalAlignment enumeration to align the text to the left, right, or in the center of a control element. 首先,建立具有特定大小的 TextBox,並在其中新增文字字串。First, create a TextBox with a specific size, and add a text string to it. 然後,使用列舉成員 Center 來對齊 TextBox中心的文字。Then, use the enumeration member Center to align the text in the center of the TextBox. 此範例假設您已建立名為 Form1Form 和名為 textBox1TextBoxThe example assumes that you have created a Form named Form1 and a TextBox named 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

備註

此列舉適用于許多類別。This enumeration is used in numerous classes. 這些類別的部分清單為 CheckedListBoxColumnHeaderComboBoxControlPaintLabelListBoxControlRichTextBoxTextBoxA partial list of these classes is CheckedListBox, ColumnHeader, ComboBox, ControlPaint, Label, ListBox, Control, RichTextBox, and TextBox.

適用於