HorizontalAlignment 枚举

定义

指定控件中的对象或文本如何相对于控件元素水平对齐。

C#
[System.Runtime.InteropServices.ComVisible(true)]
public enum HorizontalAlignment
C#
public enum HorizontalAlignment
继承
HorizontalAlignment
属性

字段

Center 2

对象或文本与控件元素的中心对齐。

Left 0

对象或文本与控件元素的左侧对齐。

Right 1

对象或文本与控件元素的右侧对齐。

示例

本示例演示如何使用 HorizontalAlignment 枚举将文本与控件元素的左、右对齐或居中对齐。 首先,创建具有特定大小的字符串 TextBox ,并向其添加文本字符串。 然后,使用枚举成员 Center 对齐中间的文本 TextBox。 该示例假定已创建命名FormForm1TextBox命名 textBox1

C#
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;							
}

注解

此枚举用于许多类。 这些类的部分列表包括CheckedListBoxColumnHeaderComboBoxControlPaintLabelListBoxControl、、和RichTextBoxTextBox

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7