HorizontalAlignment HorizontalAlignment HorizontalAlignment HorizontalAlignment Enum

定义

指定控件中的对象或文本如何相对于控件元素水平对齐。Specifies how an object or text in a control is horizontally aligned relative to an element of the control.

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

字段

Center Center Center Center 2

对象或文本与控件元素的中心对齐。The object or text is aligned in the center of the control element.

Left Left Left Left 0

对象或文本与控件元素的左侧对齐。The object or text is aligned on the left of the control element.

Right Right Right 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. 该示例假设您已创建Form一个名Form1为的和TextBox一个textBox1名为的。The 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. 这些类CheckedListBox的部分列表为Label ControlPaint ComboBoxColumnHeader、、、、 ListBox Control 、、TextBox和。 RichTextBoxA partial list of these classes is CheckedListBox, ColumnHeader, ComboBox, ControlPaint, Label, ListBox, Control, RichTextBox, and TextBox.

适用于