Reputation: 927
TabControl.TabPages.Clear();
just stopped working. It doesn't clear anything now.
Code:
private void menuItem39_Click(object sender, EventArgs e)
{
tabControl.TabPages.Clear();
}
Why would it do this?
Below is the code I use to dynamically add TabPages to the TabControl:
public void menuItem7_Click(object sender, EventArgs e)
{
tabControl.TabPages.Add(new TabPage() { Text = "Untitled" });
}
Upvotes: 0
Views: 1301
Reputation: 942255
You are writing very dangerous code, the Clear() method doesn't do what you hope it does. Start TaskMgr.exe, click the Processes tab. Use View + Select Columns and tick the USER Objects option. Locate your program in the list and keep an eye on the displayed value. Note that calling Clear() does not lower the USER Object value. In all likelihood, you'll see it climb steadily while you use your program. Very Bad Things happen when the displayed value reaches 10000.
The proper way to remove tab pages is to dispose them. Like this:
while (tabControl1.TabCount > 0) tabControl1.TabPages[0].Dispose();
Upvotes: 3