Try:
foreach (TabPage tp in myTabControl.TabPages)
{
if (tp.Text == "Page2")
{
...
break;
}
}
Or you could look at the TabPage.Name property, or use the TabControl.TabPages.Contains method if you have the whole TabPage available.
"Thanks
i followed your proposal as follows
if (customTabControl1.TabPages.Contains(Page2))
{
customTabControl1.SelectedTab = Page2;
}
else
{
customTabControl1.TabPages.Add(Page2);
customTabControl1.SelectedTab = Page2;
}
but I get the following error when I try to Select added tabpage Page2
cannot access a disposed object
Can you help me to solve the problem.
Thanks"
When you tried to hide Page2 by removing it from the list of tab pages, you didn't keep a reference to it, so the Garbage Collector has Disposed on the page - there isn't a whole lot you can do about that, other than keep a reference (which would be a good idea anyway) when you remove it.
What code are you using to show / hide tab pages?