Hiding and Showing TabPages in tabControl

KoolKabin picture KoolKabin · Jul 29, 2010 · Viewed 145.5k times · Source

I am trying to show or hide tabpages as per user choice. If user selects gender male then form for male in a tabpage "male" should be displayed and if user selects female then similar next form should be displayed in next tab "female"

I tried using

tabControl1.TabPages.Remove(...)

and

tabControl1.TabPages.Add(...)

It adds and removes the tabpages but doing so will loose my controls on tabpages too... i can't see them back. what's the problem here?

Answer

Mike picture Mike · Oct 26, 2012

I think the answer is much easier.

To hide the tab you just can use the way you already tried or adressing the TabPage itself.

TabControl1.TabPages.Remove(TabPage1) 'Could be male
TabControl1.TabPages.Remove(TabPage2) 'Could be female

a.s.o.

Removing the TabPage does not destroy it and the controls on it. To show the corresponding tab again just use the following code

TabControl1.TabPages.Insert(0, TabPage1) 'Show male
TabControl1.TabPages.Insert(1, TabPage2) 'Show female