title: How to dynamically create Tab Pages in a Tab Control with a pre-existing Windows Form in C#
body: <p>As the title suggests, I'm looking to dynamically create Tab Pages within a Tab Control. I've just begun learning C# and the app I'm making (shown below) is a generic stock price application that works great as is with a SINGLE user input. I'd like to expand it to take multiple inputs (amzn --&gt; amzn,msft,mchp).</p>
  <p>As of right now it handles multiple user inputs, but as you might guess without working Tab Controls it's just overwriting them super quick and ending on the last string in the array.</p>
  <p>I'd like to be able to have the multiple user inputs dynamically create new Tab Pages that holds all the same content as the base Form but each with different input parameters (each stock symbol). At the moment I can get it to create the new Tab Pages with the correct names without any problems, it's just populating the tabs with the content. I can get it to print to a single tab, but it won't print to all of them..</p>
  <h3>Image of base App Form (No tab implementation):</h3>
  <p><a href="https://i.stack.imgur.com/pd1O4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pd1O4.png" alt="Image of base app" /></a></p>
  <p>My biggest fear is that I'll have to do a rewrite to make it compatible with dynamically created tabs, but from all the googling I've done I haven't come across a solution that quite hits the mark for this (i.e. dynamically populating with a pre-existing form's contents)</p>
  <p>I've tried just wrapping my form content building in:</p>
  <pre><code>private void btnSubmit_Cick(object sender, EventArgs e)
  {
       string userInput = txtUserInput.Text;
       char[] delimiters = { ',', '+', ' ', '-', '_', '.' };
       string[] requests = userInput.Split(delimiters);
       foreach(string str in requests)
       {
            string requestString = str;
            var page = new TabPage(str);
              //Add content to page (i.e. page.Controls.Add(_____))
              //by cloning the base form's controls
              //then finally add the page to the tab control
            tabControl1.TabPages.Add(page);
            page.Select();
       }
  }
  </code></pre>
  <p>This method only seems to populate the last tab that is created though, it wipes out all the other prior tabs for some reason..</p>
  <p>Any help is greatly appreciated!</p>