...but when I remove the first tab from my tabcontrol the event is not trigged. The event works for all other tabs being removed (including the tab that would not trigger the event the first time)
I'm a bit confused about what's going on here. If you attached a listener to the ControlRemoved event on your tab control, the event should get fired every time a control is removed.
I'm actually quite confused by that last bit haha.
Anyway, I created a simple project and put a tab control on it with a bunch of pages. I created a button and put the following for its click event:
- private void button1_Click(object sender, EventArgs e)
-
{
-
if (tabControl1.SelectedTab != null)
-
tabControl1.TabPages.Remove(tabControl1.SelectedTab);
-
}
Then I made a listener for the ControlRemoved event with just a Console.WriteLine in it... as follows...
- TabPage senderTB = e.Control as TabPage;
-
if (senderTB != null)
-
{
-
Console.WriteLine(string.Format("TabPage, {0} ({1}), has been removed.", senderTB.Text, senderTB.Name));
-
}
When I ran it, I got my console messages as expected and none were missed.
Is there more to your code that you're posting? Maybe you've got something else going on in there...?