you can implement a property
public bool TabVisible
{
get
{
return tabControl1.Contains(tabPage2);
}
set
{
if(value == TabVisible) return;
if(value)
tabControl1.TabPages.Add(tabPage2);
else
tabControl1.TabPages.Remove(tabPage2);
}
}
you should also overwrite your disposing function,
you can move out the Dispose
function from the designer generated code to your own code, the designer notices that. you see that the components.Dispose();
function can not reach the tabPage any more for disposal, so you need to dispose it manually if it has not been disposed. otherways, especially if you are opening your window many times, you run out of window handles