Export (0) Print
Expand All

TabControl.Alignment Property

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[LocalizableAttribute(true)] 
public TabAlignment Alignment { get; set; }
/** @property */
public TabAlignment get_Alignment ()

/** @property */
public void set_Alignment (TabAlignment value)

public function get Alignment () : TabAlignment

public function set Alignment (value : TabAlignment)

Property Value

One of the TabAlignment values. The default is Top.

Exception typeCondition

InvalidEnumArgumentException

The property value is not a valid TabAlignment value.

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.

NoteNote

When visual styles are enabled, and the Alignment property is set to a value other than Top, the tabs may not render correctly.

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.

Use the System.Drawing and System.Windows.Forms namespaces for this example.

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());
    }
}

import System.Drawing.*;
import System.Windows.Forms.*;

public class Form1 extends 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.set_Alignment(System.Windows.Forms.TabAlignment.Left);

        this.tabControl1.get_Controls().AddRange(new Control[] {
            this.tabPage1, this.tabPage2, this.tabPage3 });
        this.tabControl1.set_Location(new Point(16, 24));
        this.tabControl1.set_SelectedIndex(0);
        this.tabControl1.set_Size(new Size(248, 232));
        this.tabControl1.set_TabIndex(0);

        this.tabPage1.set_TabIndex(0);
        this.tabPage2.set_TabIndex(1);
        this.tabPage3.set_TabIndex(2);

        this.set_Size(new Size(300, 300));
        this.get_Controls().AddRange(new Control[] { this.tabControl1 });
    } //MyTabs

    public Form1()
    {
        MyTabs();
    } //Form1

    public static void main(String[] args)
    {
        Application.Run(new Form1());
    } //main
} //Form1

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft