public static void InsertTabPage(this TabControl tc, TabPage tabpage, int index) { if (index < 0 || index > tc.TabCount) { throw new ArgumentException("Index out of Range."); } tc.AddTabPage(tabpage); if (index < tc.TabCount - 1) { do { tc.SwapTabPages(tabpage, (tc.TabPages[tc.TabPages.IndexOf(tabpage) - 1])); }while (tc.TabPages.IndexOf(tabpage) != index); } tc.SelectedTab = tabpage; }