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. dynamically adding tabpages to a tabcontrol

dynamically adding tabpages to a tabcontrol

Scheduled Pinned Locked Moved C#
question
4 Posts 3 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.
  • S Offline
    S Offline
    samithas
    wrote on last edited by
    #1

    I want to add tabpages to a tab control at runtime. And I should be able to specify those tabpages' names at runtime as well.HOw can I achive this? samitha

    H S 2 Replies Last reply
    0
    • S samithas

      I want to add tabpages to a tab control at runtime. And I should be able to specify those tabpages' names at runtime as well.HOw can I achive this? samitha

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      The same way the designer does it - this isn't magic like Visual Basic (6 and below). Designer code is serialized to source code; taking a look at that would be a first step to understanding. The TabControl has a collection property - TabPages - that you can add instances of a TabPage to. If you read the .NET Framework SDK for both of these classes, setting a title and adding a page to a tab control should be obvious:

      TabPage page = new TabPage("My Caption");
      tabControl1.TabPages.Add(page);

      Microsoft MVP, Visual C# My Articles

      S 1 Reply Last reply
      0
      • H Heath Stewart

        The same way the designer does it - this isn't magic like Visual Basic (6 and below). Designer code is serialized to source code; taking a look at that would be a first step to understanding. The TabControl has a collection property - TabPages - that you can add instances of a TabPage to. If you read the .NET Framework SDK for both of these classes, setting a title and adding a page to a tab control should be obvious:

        TabPage page = new TabPage("My Caption");
        tabControl1.TabPages.Add(page);

        Microsoft MVP, Visual C# My Articles

        S Offline
        S Offline
        samithas
        wrote on last edited by
        #3

        as you have mentioned I have put my code as follows //this method is called from the main windows form public void AddNewTabPage() { if(tabReportPages==null) { this.InitializeComponent(); } System.Windows.Forms.TabPage tabPage1 = new System.Windows.Forms.TabPage("test"); // // tabPage1 // tabPage1.Location = new System.Drawing.Point(4, 22); tabPage1.Name = "tabPage1"; tabPage1.Size = new System.Drawing.Size(536, 310); tabPage1.TabIndex = 0; this.tabReportPages.TabPages.Add(tabPage1); //....continues for the othe tab pages tabPage1.Show(); tabPage1.BringToFront(); tabPage2.Show(); //..continues for the other tab pages } but any of the tab pages are not showing..why is that?(the tab control is added to a user control) samitha

        1 Reply Last reply
        0
        • S samithas

          I want to add tabpages to a tab control at runtime. And I should be able to specify those tabpages' names at runtime as well.HOw can I achive this? samitha

          S Offline
          S Offline
          sreejith ss nair
          wrote on last edited by
          #4

          hi, i have a tab control with one tabpage and a button in my form. On button click i am executing this much code. TabPage Newtab=new TabPage("ha ha"); this.tabControl1.TabPages.Add(Newtab); Is the same you want ? ************************** S r e e j i t h N a i r **************************

          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