How to add tabpage to tabcontrol at 1st tab?

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
 
E

Ed Kaim

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;
 
C

Cor Ligthert

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
 
M

Mick Doherty

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
 
M

Mick Doherty

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
 
C

Cor Ligthert

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
 

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

Similar Threads


Top