We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Why is the position of the tab page in the tab control not the same during run-time and design-time sometimes?

 

The position of the tab pages during run-time is controlled by the order in which the tab pages are added to the tab control’s child controls list.

For example, if this is the code in InitializeComponent:

[C#] this.tabControlExt1.Controls.AddRange(new System.Windows.Forms.Control[] {

    this.tab1,

    this.tab4,

    this.tab2,

    this.tab3});

[VB.NET] Dim System.Windows.Forms.Control() As Me.tabControlExt1.Controls.AddRange(New {         Me.tab1,       Me.tab4,       Me.tab2,       Me.tab3     } )

... then the order in which the tab pages are shown during run-time will be 1, 4, 2, 3.

Unfortunately while serializing, the designer code generation logic moves the recently activated child (tab page) to the top of the order even if the tab order hasn’t changed.

This buggy behavior can be see even when working with the .NET TabControl. We have reported this to Microsoft and are expecting a fix for this issue. We are also trying to internally workaround this issue on a case by case basis, so please report a reproducable scenario to us via a Support Incident on our website.

Workaround:

You may work around this issue in the mean time by doing something like this in the form’s constructor:

[C#] public Form1_InitUsingDesigner()

{

 InitializeComponent();

 // Reset the order in which the tab pages are added.   

 this.tabControlExt1.Controls.Clear();

 // To add the tab pages in the order 1, 2, 3, 4

 this.tabControlExt1.Controls.AddRange(new System.Windows.Forms.Control[] {

    this.tab1,

    this.tab2,

    this.tab3,

    this.tab4});

}

[VB.NET] Private Function Form1_InitUsingDesigner() As Public    InitializeComponent()    ' Reset the order in which the tab pages are added.       Me.tabControlExt1.Controls.Clear()    ' To add the tab pages in the order 1, 2, 3, 4    Dim System.Windows.Forms.Control() As Me.tabControlExt1.Controls.AddRange(New  {       Me.tab1,       Me.tab2,       Me.tab3,       Me.tab4     } )   End Function

Article ID: Published Date: Last Revised Date: Platform: Control:
1189 04/30/2011 07/10/2014 Windows Forms TabControlAdv
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.