How to add tabpage to tabcontrol at 1st tab?

  • Thread starter Thread starter Tee
  • Start date Start date
T

Tee

Hi,

I have a tabcontrol that has a tabpage, I want to add another tabpage on
runtime, but I want the tabpage to be added to the 1st tab, anyone know how
to do it?


Thanks,
Tee
 
There's probably a better way, but some C# code that seems to work is:
TabPage p = new TabPage("My Tab Page");

this.tabControl1.TabPages.Add(p);

for (int lcv = this.tabControl1.TabPages.Count - 1; lcv > 0; lcv--)

{

this.tabControl1.TabPages[lcv] = this.tabControl1.TabPages[lcv - 1];

}

this.tabControl1.TabPages[0] = p;
 
Tee,

Because of a bug in the tabpages, you have probably first to "remove" all
the existing ones and than "add" again all the ones in the sequence that you
want them.

Cor
 
Cor Ligthert said:
Tee,

Because of a bug in the tabpages, you have probably first to "remove" all
the existing ones and than "add" again all the ones in the sequence that
you want them.

Cor

No! Don't remove tabpages as this will cause unsightly flicker. Simply swap
tabpages.

On my site you'll find routines for inserting a tabpage which uses a loop to
swap tabpages until the new tabpage is where you want it.
http://dotnetrix.co.uk/tabcontrols.html --> Hide and show tabpages in
Tabcontrol
 
There's no better way ;-)

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


Ed Kaim said:
There's probably a better way, but some C# code that seems to work is:
TabPage p = new TabPage("My Tab Page");

this.tabControl1.TabPages.Add(p);

for (int lcv = this.tabControl1.TabPages.Count - 1; lcv > 0; lcv--)

{

this.tabControl1.TabPages[lcv] = this.tabControl1.TabPages[lcv - 1];

}

this.tabControl1.TabPages[0] = p;


Tee said:
Hi,

I have a tabcontrol that has a tabpage, I want to add another tabpage on
runtime, but I want the tabpage to be added to the 1st tab, anyone know
how
to do it?


Thanks,
Tee
 
Mick,

Everything can be done better, however to say a screaming "No" to it is in
my opinion overdone.

Not angry, just friendly laughing.

Cor
 
Back
Top