Child form opens in a new window

996 views Asked by At

My child form opens up in a new window instead of opening within the MDI form when I use the below code:

Form1 f1 = new Form1();
f1.Dock = DockStyle.Fill;
f1.MdiParent = this.MdiParent;

this.WindowState = FormWindowState.Maximized;

f1.Show(); 
1

There are 1 answers

4
haystackoverflow On

As @Keyur PATEL in comment suggested, you should set parent of "f1" form to the form object(not object MdiParent property) in which you want to inject "f1" form as MDI Child form ( not to the property of parent form, but to the object itself).

See more on Microsoft docs about MDI Apps.

Form1 f1 = new Form1();
f1.Dock = DockStyle.Fill;//This is not necessary,can work without it
f1.MdiParent = this; //try like this

this.WindowState = FormWindowState.Maximized;

f1.Show();