TopLevel controls (like Form) cannot be added into Controls list using Controls.Add(). For example, if you are trying to add a form into a Panel’s control list, it will lead you to an exception ‘Top-level control cannot be added to a control’. To avoid this exception, you need to set the form’s TopLevel property to false.
Form form2 = new Form();
form2.TopLevel = false;
this.panel1.Controls.Add(form2);
Share with