By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,900 Members | 1,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,900 IT Pros & Developers. It's quick & easy.

Please help me with this TabPage question...

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
This should be relatively simple. Try using this:

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

"JG" <nospam> wrote in message news:eK**************@tk2msftngp13.phx.gbl...
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

Nov 15 '05 #2

P: n/a
JG
Thank you very much... Can't see the forest for the trees...

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.