Please help me with this TabPage question...

J

JG

Hi,

I have a windows form with a TabControl on it. It has 3 tabpages on it. I
have also coded a button that is supposed to 'add' a new tabpage.

The code in that clicked event looks like this:

tabPage tpNew = new TabPage("TabPage4");
this.tabControl1.TabPages.Add(tpNew);
tpNew.Controls.Add(this.label1);

No problem. It works just fine and adds the new tabpage to tabControl1. Note
in that tabpage that a label is also added. This too works just fine.

Now my question is this: how do I despose of that 'new' tabpage. I have
coded another button on my test winform and it desposes of the tabpages on
tabControl. It looks something like this:

tabPage2.Dispose();
tabPage3.Dispose();

Now, how do I dispose of the tabpage that I have added in the code above? I
have tried several things, but cannot get that one to go away...

Any help would be greately appreciated. Regards,
joe
 
R

Ron Rohrssen

This should be relatively simple. Try using this:

if (this.tabControl1.TabPages.Count > 0)
{
this.tabControl1.TabPages.RemoveAt(this.tabControl1.SelectedIndex);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top