HorizontalAlignment 列舉

定義

指定控制項中的物件或文字如何水平對齊於相關的控制項項目。

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
繼承
HorizontalAlignment
屬性

欄位

Center 2

物件或文字置中對齊控制項項目。

Left 0

物件或文字靠左對齊控制項項目。

Right 1

物件或文字靠右對齊控制項項目。

範例

這個範例示範如何使用 HorizontalAlignment 列舉,將文字對齊控制項專案的左、右或中央。 首先,建立 TextBox 具有特定大小的 ,並將文字字串新增至其中。 然後,使用列舉成員 Center 來對齊 中央的 TextBox 文字。 此範例假設您已建立 Form 具名 Form1TextBox 具名 的 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

備註

這個列舉用於許多類別。 這些類別的部分清單為 CheckedListBoxColumnHeaderComboBoxControlPaintLabelListBoxControlRichTextBox 、 和 TextBox

適用於