Articles in this section
Category / Section

What is the reason for position of the tab page in the WinForms TabControlAdv not the same during run-time?

2 mins read

Position of the tab page

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

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 seeing 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

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

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied