HorizontalAlignment 枚举
指定控件中的对象或文本如何相对于控件元素水平对齐。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
<ComVisibleAttribute(True)> _
Public Enumeration HorizontalAlignment
用法
Dim instance As HorizontalAlignment
[ComVisibleAttribute(true)]
public enum HorizontalAlignment
[ComVisibleAttribute(true)]
public enum class HorizontalAlignment
/** @attribute ComVisibleAttribute(true) */
public enum HorizontalAlignment
ComVisibleAttribute(true)
public enum HorizontalAlignment
成员
成员名称 | 说明 | |
---|---|---|
Center | 对象或文本与控件元素的中心对齐。 | |
Left | 对象或文本与控件元素的左侧对齐。 | |
Right | 对象或文本与控件元素的右侧对齐。 |
备注
该枚举用于许多类。这些类的部分列表包括:CheckedListBox、ColumnHeader、ComboBox、ControlPaint、Label、ListBox、Control、RichTextBox 和 TextBox。
示例
该示例说明如何使用 HorizontalAlignment 枚举来使文本与控件元素左对齐、右对齐或中心对齐。首先,创建一个特定大小的 TextBox,并为其添加一个文本字符串。然后,使用枚举成员 Center 使文本与 TextBox 的中心对齐。该示例假定已经创建一个名为 Form1
的 Form 和一个名为 textBox1
的 TextBox。
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
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:
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.set_Text("Hello World!");
// Set the size of the TextBox.
textBox1.set_AutoSize(false);
textBox1.set_Size(new Size(get_Width(), get_Height() / 3));
// Align the text in the center of the control element.
textBox1.set_TextAlign(HorizontalAlignment.Center);
} //Form1_Load
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0