HI all,
I have this code in which the window property of making child window load at the center of mdiparent.
Form2 f = new Form2();
f.MdiParent = this;
//center screen is working.
//f.StartPosition = FormStartPosition.CenterScreen;
f.StartPosition = FormStartPosition.CenterParent;
but instead of making the child window pop at the center it loads at the left side. Can anyone help me on this. Please refer the screenshot below.
I have even tried doing the same in vb. Even there i get the same error. I think the property of FormStartPosition.CenterParent is dummy.
alt text http://img13.imageshack.us/img13/7003/errorprb.jpg
The MDICLIENT window manages the client area of the main frame window, and itself has child windows: the document windows, derived from CMDIChildWnd . Because the document windows are frame windows themselves (MDI child windows), they can also have their own children.
Click on New Menu Item and generate a Click Event Handler on it. Now Double click on New Menu Item and Write down the following Code. Form2 newMDIChild = newForm2(); // Set the Parent Form of the Child window.
I experimented a bit with this, and first came to the same solution as Patrick. But I was bugged by the following statement in the documentation of the StartPosition
property:
You can also position the form to display in the center of the screen or in the center of its parent form for forms such as multiple-document interface (MDI) child forms.
So, I decided that there must be a way. And there is, though I don't find it all intuitive: set the StartPosition
to CenterScreen
(not CenterParent
):
MdiChildUI form = new MdiChildUI();
form.MdiParent = this;
form.StartPosition = FormStartPosition.CenterScreen;
form.Show();
Of course, you can also set it in the designer instead of in code.
Setting start position as center screen works perfect for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With