如何从 MDIChild 表单中正确显示 ShowDialog()?
我有一个 MDIChild 窗体需要显示一个对话框。 我目前正在 mdichild 表单中这样做...
f.ShowDialog(Me)
我应该使用 f.ShowDialog(mdiparent)
吗?
在调用 ShowDialog()
之前设置所有者有什么区别?
I have an MDIChild form that needs to show a dialog. I'm currently doing it like this from inside the mdichild form...
f.ShowDialog(Me)
Should I be using f.ShowDialog(mdiparent)
?
What is the difference when setting the owner before calling ShowDialog()
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定这是否相关,但我在 ShowDialog 中传递所属表单时遇到了一些问题,我通常这样做:
I'm not sure if this is related, but I've had some issues with passing the owning form in ShowDialog, I usually do this:
区别在于哪个父级拥有该对话框。 如果您显式设置父窗口,则该窗口拥有该对话框。 如果您没有设置它(使用 ShowDialog 的无参数版本),则应用程序的当前活动窗口拥有该对话框。 顺便说一句,这是在 MSDN 上。
这在通过使用 FormStartPosition.CenterParent 枚举设置 StartPosition 属性来使对话框居中时有用。
The difference is in which parent owns the dialog. If you explicitly set the parent then that window owns the dialog. If you don't set it (using the parameterless version of ShowDialog) then the current active window of your application owns the dialog. That's on MSDN, btw.
Where this is useful is in centering your dialog by setting the StartPosition property using the FormStartPosition.CenterParent enumeration.
它确实有所不同...
我有一个调用 ShowDialog(Me) 的 MDI 子项,在生成的对话框窗口中,Me.Owner 引用 MDI 容器,而不是 MDI 子项。
使用 Me.Owner.ActiveControl 是一种解决方法,但使用:
可以很好地获取它。 在生成的对话框窗口中,Me.Owner 现在确实引用了 MDI 子项。
希望这可以帮助!
It does make a difference...
I have an MDI child that calls ShowDialog(Me) and in the resulting dialog window, Me.Owner references the MDI container, not the MDI child.
Using Me.Owner.ActiveControl is a workaround, but using:
Gets it nicely. In the resulting dialog window, Me.Owner now does reference the MDI child.
Hope this helps!