HorizontalAlignment Enumeration
Specifies how an object or text in a control is horizontally aligned relative to an element of the control.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
This enumeration is used in numerous classes. A partial list of these classes is CheckedListBox, ColumnHeader, ComboBox, ControlPaint, Label, ListBox, Control, RichTextBox, and TextBox.
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. First, create a TextBox with a specific size, and add a text string to it. Then, use the enumeration member Center to align the text in the center of the TextBox. The example assumes that you have created a Form named Form1 and a TextBox named textBox1.
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
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
