Search code examples
c#windowswinformstabpage

Is it possible to add an already created form to a tab control?


With this setup:

 Form1 
      tabControl1
           tab1
           tab2
 Form2
      button1
      textbox1

Is it possible to add Form2 to tab 2? So if I were to click on tab2, Form2 would show up within that tab?


Solution

  • "@Idle_Mind Nailed it, thank you. – Blankdud"

    It's possible by setting the TopLevel property of your Form2 instance to false at run-time, and then adding it to the TabPage controls collection before calling Show(). Note, however, that controls displayed in forms this way do not behave correctly with respect to tabbing. Use a UserControl instead of a form.