Reputation: 17
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();
Upvotes: 0
Views: 1053
Reputation: 33
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();
Upvotes: 2