Inserting a tabpage
-
Does anyone know of any way to insert a tabpage into a tabcontrol? I don't want to tack the page onto the end with Add() I want to be able to insert it at any position. Anyone know of a way to do this? Thanks in advance. - monrobot13
-
Does anyone know of any way to insert a tabpage into a tabcontrol? I don't want to tack the page onto the end with Add() I want to be able to insert it at any position. Anyone know of a way to do this? Thanks in advance. - monrobot13
I don't know of a way to do it directly, but it's fairly easy to do by shuffling the tab pages around. For example:
private static void AddTabPageAtIndex(TabControl tc, TabPage tp, int index) { // Get index into sensible range if (index < 0) index = 0; else if (index > tc.TabCount) index = tc.TabCount; // Add a dummy page to the end tc.TabPages.Add(new TabPage()); // Copy tab pages that are to be after new one for (int i = tc.TabCount-1; i > index ; --i) tc.TabPages[i] = tc.TabPages[i-1]; // Insert the new page tc.TabPages[index] = tp; }
Chris Jobson -
I don't know of a way to do it directly, but it's fairly easy to do by shuffling the tab pages around. For example:
private static void AddTabPageAtIndex(TabControl tc, TabPage tp, int index) { // Get index into sensible range if (index < 0) index = 0; else if (index > tc.TabCount) index = tc.TabCount; // Add a dummy page to the end tc.TabPages.Add(new TabPage()); // Copy tab pages that are to be after new one for (int i = tc.TabCount-1; i > index ; --i) tc.TabPages[i] = tc.TabPages[i-1]; // Insert the new page tc.TabPages[index] = tp; }
Chris JobsonThanks for the info Chris. It's a big help. - monrobot13