'How do I add form on tab control in c#

I have a form page with text boxes and data grid view and other forms that contain a tab control. I want to add the first form tab in the second form. I tried to write the code for the form to appear but it is larger than the tab container and doesn't fit. Only half of the form appears.

This is my code:

private void tcMainPage_SelectedIndexChanged(object sender, EventArgs e)
{
      if (tcMainPage.SelectedIndex == 0)
      {
          GTOWN.PrintingPage BookInfo = new PrintingPage();
          BookInfo.TopLevel = false;
          BookInfo.FormBorderStyle = FormBorderStyle.None;
          BookInfo.Dock = DockStyle.Fill;
          tpSearch.Controls.Add(BookInfo);
          BookInfo.Show();
       }    
}

this is the form

and that is what appears



Solution 1:[1]

Set your main FORM as a Container.

yourForm.IsMdiContainer = true;

Then add the child form to the tabPage:

private void tcMainPage_SelectedIndexChanged(object sender, EventArgs e)
{
    if (tcMainPage.SelectedIndex == 0)
    {
        PrintingPage newFrm = new PrintingPage
        {
            MdiParent = this,
            // This set the form parent as the tabClicked
            Parent = tcMainPage.TabPages[0]
        };
        newFrm.Show();
    }
}

Solution 2:[2]

my tab form work good in the same code

thank you all my code was correct but the problem was in tab property i deleted the tab and add another one and the code is working now

thank you

Solution 3:[3]

I face this issue and I create this if may help

public void addform(TabPage tp, Form f)
    {                      
        
        f.TopLevel = false;
        //no border if needed
        f.FormBorderStyle = FormBorderStyle.None;            
        f.AutoScaleMode = AutoScaleMode.Dpi;
        
        if (!tp.Controls.Contains(f))
        {
            tp.Controls.Add(f);
            f.Dock = DockStyle.Fill;
            f.Show();
            Refresh();
        }
        Refresh();            
    }

Solution 4:[4]

Forms are top-most objects and cannot be placed inside of other containers.

You may want to refactor your code so that the items on your Form are on a UserControl instead. At that point you can then add that UserControl to both a Form and a TabControl

public UserControl myControl(){ /* copy your current view code here */}

public Form myForm(){
  Controls.Add(new myControl());
}

public Form myTabbedForm(){
  var tabControl = new TabControl();
  var page1 = new TabPage();
  page1.Controls.Add(new myControl());
  tabControl.TabPages.Add(page1);
  this.Controls.Add(tabControl);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 Ahmed Fekry
Solution 4 Bill Tarbell