如何使mdichild加载在mdiparent窗口的中心

发布于 2024-08-01 17:54:38 字数 590 浏览 1 评论 0原文

大家好,

我有这段代码,其中使子窗口加载的 window 属性位于 mdiparent 的中心。

        Form2 f = new Form2();

        f.MdiParent = this;

        //center screen is working.

        //f.StartPosition = FormStartPosition.CenterScreen;

        f.StartPosition = FormStartPosition.CenterParent;

但子窗口不是在中心弹出,而是在左侧加载。 谁可以帮我这个事。 请参考下面的屏幕截图。

我什至尝试过在 VB 中做同样的事情。 即使在那里我也遇到同样的错误。 我认为 FormStartPosition.CenterParent 的属性是虚拟的。

替代文本 http://img13.imageshack.us/img13/7003/errorprb.jpg

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烟柳画桥 2024-08-08 17:54:38

我对此进行了一些尝试,首先得出了与帕特里克相同的解决方案。 但我被 文档中的以下声明所困扰StartPosition 属性

您还可以将表单定位到
显示在屏幕中央或
在其父窗体的中心
多文档等形式
界面(MDI)子窗体。

所以,我决定一定有办法。 还有,虽然我觉得这并不直观:将 StartPosition 设置为 CenterScreen不是 CenterParent ):

MdiChildUI form = new MdiChildUI();
form.MdiParent = this;
form.StartPosition = FormStartPosition.CenterScreen;
form.Show();

当然,你也可以在设计器中设置,而不是在代码中设置。

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.

ペ泪落弦音 2024-08-08 17:54:38

将起始位置设置为中心屏幕对我来说非常适合。

Setting start position as center screen works perfect for me.

凉墨 2024-08-08 17:54:38

我尝试将 MDI 容器表单显示为所有者,但给我带来了异常。 您可以在显示子项之前手动设置位置,如下所示:

Form2 f = new Form2();
f.MdiParent = this;
f.StartPosition = FormStartPosition.Manual;
f.Location = new Point((this.ClientSize.Width - f.Width) / 2,
                       (this.ClientSize.Height - f.Height) / 2);
f.Show();

编辑:

f.StartPosition = FormStartPosition.CenterScreen;

是将 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:

Form2 f = new Form2();
f.MdiParent = this;
f.StartPosition = FormStartPosition.Manual;
f.Location = new Point((this.ClientSize.Width - f.Width) / 2,
                       (this.ClientSize.Height - f.Height) / 2);
f.Show();

EDIT:

f.StartPosition = FormStartPosition.CenterScreen;

is the correct way to center an mdichild on its parent form.

没︽人懂的悲伤 2024-08-08 17:54:38

表单具有 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文