Basically, when a user logs out of my system I am trying to use a loop to loop through all the tabs in the tabcontrol and remove them, before adding the login tab back on there. Here's my code:
Expand|Select|Wrap|Line Numbers
- MessageBox.Show(Convert.ToString(tabControl1.TabCount));
- for (int i = 0; i <= tabControl1.TabCount; i++)
- {
- tabControl1.TabPages.RemoveAt(i);
- }
- logoutlabel.Visible = false;
- FirstLogin();
I get the "index [number] is out of range". Sometimes it'll remove the last two tabs, sometimes it'll just error straight away. I'm not sure what I'm doing wrong here. Please help me out!