HorizontalAlignment 枚举 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定控件中的对象或文本如何相对于控件元素水平对齐。
public enum class HorizontalAlignment[System.Runtime.InteropServices.ComVisible(true)]
public enum HorizontalAlignmentpublic enum HorizontalAlignment[<System.Runtime.InteropServices.ComVisible(true)>]
type HorizontalAlignment = type HorizontalAlignment = Public Enum HorizontalAlignment- 继承
- 属性
字段
| Center | 2 | 对象或文本与控件元素的中心对齐。 | 
| Left | 0 | 对象或文本与控件元素的左侧对齐。 | 
| Right | 1 | 对象或文本与控件元素的右侧对齐。 | 
示例
本示例演示如何使用 HorizontalAlignment 枚举将文本与控件元素的左、右对齐或居中对齐。 首先,创建具有特定大小的字符串 TextBox ,并向其添加文本字符串。 然后,使用枚举成员 Center 对齐中间的文本 TextBox。 该示例假定已创建命名FormForm1和TextBox命名 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
注解
此枚举用于许多类。 这些类的部分列表包括CheckedListBox、ColumnHeader、ComboBox、ControlPaintLabel、ListBox、Control、、和RichTextBoxTextBox。