Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Inserting a tabpage

Inserting a tabpage

Scheduled Pinned Locked Moved C#
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    monrobot13
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • M 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

      C Offline
      C Offline
      Chris Jobson
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • C 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 Jobson

        M Offline
        M Offline
        monrobot13
        wrote on last edited by
        #3

        Thanks for the info Chris. It's a big help. - monrobot13

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups