Namrata Kongutte Namrata Kongutte - 2 months ago 31
C# Question

Hiding TabPage from TabControl in Winform application

I have a TabControl in Winform s application,
I have to disable the second tab, clicking it would be enabled only after some action on my first page.
I have achieved this by disabling tab by code

tabControl1.TabPages[1].Enabled = false;


But I want that tab to be hidden or clicking the tab itself should be disabled.

Answer

Try This. It will hide and show the TabPages without a Control lost.

Hide TabPage and Remove the Header:

this.tabPage1.Hide();
this.tabPage3.Hide();
this.tabPage5.Hide();
tabControl1.TabPages.Remove(tabPage1);
tabControl1.TabPages.Remove(tabPage3);
tabControl1.TabPages.Remove(tabPage5);

Show TabPage and Visible the Header:

tabControl1.TabPages.Insert(0,tabPage1);
tabControl1.TabPages.Insert(2, tabPage3);
tabControl1.TabPages.Insert(4, tabPage5);
this.tabPage1.Show();
this.tabPage3.Show();
this.tabPage5.Show();
tabControl1.SelectedTab = tabPage1;
Comments