如何使mdichild加载在mdiparent窗口的中心
大家好,
我有这段代码,其中使子窗口加载的 window 属性位于 mdiparent 的中心。
Form2 f = new Form2();
f.MdiParent = this;
//center screen is working.
//f.StartPosition = FormStartPosition.CenterScreen;
f.StartPosition = FormStartPosition.CenterParent;
但子窗口不是在中心弹出,而是在左侧加载。 谁可以帮我这个事。 请参考下面的屏幕截图。
我什至尝试过在 VB 中做同样的事情。 即使在那里我也遇到同样的错误。 我认为 FormStartPosition.CenterParent 的属性是虚拟的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我对此进行了一些尝试,首先得出了与帕特里克相同的解决方案。 但我被 文档中的以下声明所困扰
StartPosition
属性:所以,我决定一定有办法。 还有,虽然我觉得这并不直观:将
StartPosition
设置为CenterScreen
(不是CenterParent
):当然,你也可以在设计器中设置,而不是在代码中设置。
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:So, I decided that there must be a way. And there is, though I don't find it all intuitive: set the
StartPosition
toCenterScreen
(notCenterParent
):Of course, you can also set it in the designer instead of in code.
将起始位置设置为中心屏幕对我来说非常适合。
Setting start position as center screen works perfect for me.
我尝试将 MDI 容器表单显示为所有者,但给我带来了异常。 您可以在显示子项之前手动设置位置,如下所示:
编辑:
是将 mdichild 置于其父窗体中心的正确方法。
I tried showing the child with the MDI container form as owner, but caused an exception for me. You could manually set the location before showing the child as follows:
EDIT:
is the correct way to center an mdichild on its parent form.
表单具有 MdiParent 属性和 Parent 属性。
请注意,MdiParent 不是 MdiChild 表单的父表单。
它是,它的 MdiParent;
所以 CenterToParent 方法对于这些类型的表单来说是没有意义的。
当您为多监视器应用程序编程时,或者通过将其 Toplevel 属性设置为 false 并将其设置为 false 来在另一个表单中托管一个表单时,您可以看到 CenterToParent 方法的功能。另一种形式的父属性。
祝你好运,
阿拉姆·阿夫萨
A form has an MdiParent property and a Parent property.
Please notice that an MdiParent IS NOT the parent of MdiChild form.
It is, its MdiParent;
So CenterToParent Method is meaningless for these types of forms.
You can see the functionality of CenterToParent Method when you program for multiple monitors application, or when you host a form inside another form by setting its Toplevel property to false, and setting its Parent property to another form.
Good Luck,
Aram Afsar