How to change the sequence of the tabpage in the tabcontrol ?

  • Thread starter Thread starter james ou
  • Start date Start date
The order of the tabs is determined by the order in which they were added to
the TabControl.Controls collection. So, if you just want to tweak the
display order initially, then you can just reaarange this order in the
designer generated code. But the change would probably have to be redone at
some point if teh designer regenerates teh code from scratch again for some
reason. So, you could avoid this regneration problem by clearing teh
Controls collection and adding them again in teh proper order in Form.Load.

this.tabControl1.Controls.Clear();
this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabPage4,
this.tabPage2,
this.tabPage3,
this.tabPage1});


At runtime, you can swap tab order with code like:

private void SwapTabs(int tab1, int tab2)
{
TabPage tab = this.tabControl1.TabPages[tab1];
this.tabControl1.TabPages[tab1] = this.tabControl1.TabPages[tab2];
this.tabControl1.TabPages[tab2] = tab;

if(this.tabControl1.SelectedIndex == tab1)
this.tabControl1.SelectedIndex = tab2;
else if(this.tabControl1.SelectedIndex == tab2)
this.tabControl1.SelectedIndex = tab1;
}


=================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
Change the TabIndex in the designer generated region for
each tabPage,

i.e. this.tabPageX.TabIndex = 0;

I found that this was wrong, despite the fact that i'd
set the index in the designer.

Regards,

-----Original Message-----
The order of the tabs is determined by the order in which they were added to
the TabControl.Controls collection. So, if you just want to tweak the
display order initially, then you can just reaarange this order in the
designer generated code. But the change would probably have to be redone at
some point if teh designer regenerates teh code from scratch again for some
reason. So, you could avoid this regneration problem by clearing teh
Controls collection and adding them again in teh proper order in Form.Load.

this.tabControl1.Controls.Clear();
this.tabControl1.Controls.AddRange(new
System.Windows.Forms.Control[] {
this.tabPage4,
this.tabPage2,
this.tabPage3,
this.tabPage1});


At runtime, you can swap tab order with code like:

private void SwapTabs(int tab1, int tab2)
{
TabPage tab = this.tabControl1.TabPages[tab1];
this.tabControl1.TabPages[tab1] = this.tabControl1.TabPages[tab2];
this.tabControl1.TabPages[tab2] = tab;

if(this.tabControl1.SelectedIndex == tab1)
this.tabControl1.SelectedIndex = tab2;
else if(this.tabControl1.SelectedIndex == tab2)
this.tabControl1.SelectedIndex = tab1;
}


=================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

as the title

thanks


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top