如何CenterParent非模态窗体

编程入门 行业动态 更新时间:2024-10-27 02:30:29
本文介绍了如何CenterParent非模态窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个从父窗体开辟了一个非模态子窗体。我需要给孩子表格中心其父形式。我已经设置子窗体的属性 CenterParent ,并试图这样的:

I have a non-modal child form which opens up from a parent form. I need to center the child form to its parent form. I have set property of child form to CenterParent and tried this:

Form2 f = new Form2(); f.Show(this);

但无济于事。这适用于模态的形式,但不能因此与非模态形式。任何简单的解决方案,还是需要我去通过所有的数学计算来解决它的位置居中?

but to no avail. This works with modal form, but not so with non-modal forms. Any simple solution, or need I go through all that mathematical calculation to fix its position to center?

推荐答案

恐怕 StartPosition.CenterParent 仅用于模态对话框好( .ShowDialog )。结果你必须手动设置的位置这样:

I'm afraid StartPosition.CenterParent is only good for modal dialogs (.ShowDialog). You'll have to set the location manually as such:

Form f2 = new Form(); f2.StartPosition = FormStartPosition.Manual; f2.Location = new Point(this.Location.X + (this.Width - f2.Width) / 2, this.Location.Y + (this.Height - f2.Height) / 2); f2.Show(this);

更多推荐

如何CenterParent非模态窗体

本文发布于:2023-11-03 07:50:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗体   模态   CenterParent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!