TabControl.Alignment Property

Definition

Gets or sets the area of the control (for example, along the top) where the tabs are aligned.

C#
public System.Windows.Forms.TabAlignment Alignment { get; set; }

Property Value

One of the TabAlignment values. The default is Top.

Exceptions

The property value is not a valid TabAlignment value.

Examples

The following code example creates a TabControl with three TabPage objects. The Alignment property is set to Left, which positions the tabs of tabControl1 on the left side.

C#
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
{
    private TabControl tabControl1;
    private TabPage tabPage1;
    private TabPage tabPage2;
    private TabPage tabPage3;

    private void MyTabs()
    {
        this.tabControl1 = new TabControl();
        this.tabPage1 = new TabPage();
        this.tabPage2 = new TabPage();
        this.tabPage3 = new TabPage();

        // Positions tabs on the left side of tabControl1.
        this.tabControl1.Alignment = System.Windows.Forms.TabAlignment.Left;

        this.tabControl1.Controls.AddRange(new Control[] {
            this.tabPage1,
            this.tabPage2,
            this.tabPage3});
        this.tabControl1.Location = new Point(16, 24);
        this.tabControl1.SelectedIndex = 0;
        this.tabControl1.Size = new Size(248, 232);
        this.tabControl1.TabIndex = 0;

        this.tabPage1.TabIndex = 0;
        this.tabPage2.TabIndex = 1;
        this.tabPage3.TabIndex = 2;

        this.Size = new Size(300,300);
        this.Controls.AddRange(new Control[] {
            this.tabControl1});
    }

    public Form1()
    {
        MyTabs();
    }

    static void Main() 
    {
        Application.Run(new Form1());
    }
}

Remarks

When the Alignment property is set to Left or Right, the Multiline property is automatically set to true.

When you set the Appearance property to FlatButtons, it only appears as such when the Alignment property is set to Top. Otherwise, the Appearance property displays as if set to the Buttons value.

When you set the Appearance property to Buttons, you must also set the Alignment property to Top so that the buttons display correctly.

Note

When you set the Appearance property to Buttons, you must also set the Alignment property to Top so that the tab page contents display correctly. Additionally, when visual styles are enabled, and the Alignment property is set to a value other than Top, the tab contents may not render correctly.

Applies to

Product Versions
.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, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also