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?
To hide a tab: tabControl. TabPages. Remove(tabPage);
To hide tabs in IntegralUI TabControl is simple, just set the Visible property value to false, and the designated tab will become hidden. The tab still exists in Pages collecton of TabControl, only it is not shown in tab strip.
The Hide method of the TabPage will not hide the tab. To hide the tab, you must remove the TabPage control from the TabControl..::. TabPages collection.
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
You could remove the tab page from the TabControl.TabPages collection and store it in a list. For example:
private List<TabPage> hiddenPages = new List<TabPage>(); private void EnablePage(TabPage page, bool enable) { if (enable) { tabControl1.TabPages.Add(page); hiddenPages.Remove(page); } else { tabControl1.TabPages.Remove(page); hiddenPages.Add(page); } } protected override void OnFormClosed(FormClosedEventArgs e) { foreach (var page in hiddenPages) page.Dispose(); base.OnFormClosed(e); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With