Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Team,

I am using C# 3.0 in my application.
Windows form having TabControl with 5 TabPages.
As per Data I am populated only required Tabs and Rest I am deleting as shown below -
C#
tabControl1.Controls.Remove(MytabPage1);

Now I want to check - Which Tabs I have removed and which tabs are now visible on Windows Form.

Please help.
Posted
Updated 17-Dec-14 21:24pm
v2

1 solution

I suggest you define a List<TabPage> to hold the removed TabPages, and provide a 'ControlRemoved EventHandler for the TabControl:
C#
private List<tabpage> RemovedTabs;

private void Form1_Load(object sender, EventArgs e)
{
    RemovedTabs = new List<tabpage>();

    YourTabControl.ControlRemoved += YourTabControl_ControlRemoved;
}

private void YourTabControl_ControlRemoved(object sender, ControlEventArgs e)
{
    // for testing only
    Console.WriteLine("removed TabPage {0}", e.Control.Name);
    
    RemovedTabs.Add(e.Control as TabPage);
}</tabpage></tabpage>
Note that removed TabPages are not Disposed ! So, if you want to Dispose a TabPage, you should remove it from the 'RemovedTabs List before you call 'Dispose.

Using this technique you can check which TabPages are "open" by simply enumerating the TabControl.TabPages TabPagesCollection, and check which Tabs have been removed by enumerating the list in 'RemovedTabs.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900