1

I have 2 Forms and i want them to be inserted into a form with a tabcontrol. I have read this question about adding forms to tabcontrols and Form1 is successfully inserted into the tabcontrol. Form2 is also inserted but the content of the form is not showing.

This is my code:

   private FrmMainForm trackIT = new FrmMainForm();
   private MainForm customer = new MainForm();

   private void TrackITForm_Load(object sender, EventArgs e)
        {
            AddNewForm(trackIT, trackitTab);
            AddNewForm(customer, customerTab);
        }

    public void AddNewForm(Form form, TabPage tab)
    {
        form.WindowState = FormWindowState.Maximized;
        form.TopLevel = false;
        form.Parent = tab;
        form.Visible = true;
    }

I also have set my parent Form's IsMDIContainer property to true.

What can be the issue here?

Community
  • 1
  • 1
Lahib
  • 1,305
  • 5
  • 34
  • 62

1 Answers1

2
  1. I also have set my parent Form's IsMDIContainer property to true : Don't do that. You're not doing MDI.
  2. In AddNewForm(), set the WindowState property after all the others.
  3. I think (not 100% sure) that Visble=true is not enough, call form.Show() instead. Do it after setting the WindowState and especially the Parent.
  4. Check the forms for conflicting properties in the designer code and FormLoad.
  5. Consider using UserControls instead of Forms. They are meant to be embedded.
H H
  • 263,252
  • 30
  • 330
  • 514