简体   繁体   中英

Child form opens in a new window

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(); 

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(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM