Export (0) Print
Expand All
Expand Minimize

HorizontalAlignment Enumeration

Specifies how an object or text in a control is horizontally aligned relative to an element of the control.

[Visual Basic]
<Serializable>
<ComVisible(True)>
Public Enum HorizontalAlignment
[C#]
[Serializable]
[ComVisible(true)]
public enum HorizontalAlignment
[C++]
[Serializable]
[ComVisible(true)]
__value public enum HorizontalAlignment
[JScript]
public
   Serializable
 ComVisible(true)
enum HorizontalAlignment

Remarks

This enumeration is used in numerous classes. A partial list of these classes is CheckedListBox, ColumnHeader, ComboBox, ControlPaint, Label, ListBox, Control, RichTextBox, and TextBox.

Members

Member name Description
Center

Supported by the .NET Compact Framework.

The object or text is aligned in the center of the control element.
Left

Supported by the .NET Compact Framework.

The object or text is aligned on the left of the control element.
Right

Supported by the .NET Compact Framework.

The object or text is aligned on the right of the control element.

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
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

[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;                            
}

[C++] 
private:
    void Form1_Load(Object* /*sender*/, System::EventArgs* /*e*/) {
        // Add a text String* to the TextBox.
        textBox1->Text = S"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;
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

System.Windows.Forms Namespace

Show:
© 2014 Microsoft