如何从 MDIChild 表单中正确显示 ShowDialog()?

发布于 2024-07-12 08:18:14 字数 211 浏览 5 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(3

白衬杉格子梦 2024-07-19 08:18:14

我不确定这是否相关,但我在 ShowDialog 中传递所属表单时遇到了一些问题,我通常这样做:

f.Owner = Me
f.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:

f.Owner = Me
f.ShowDialog()
与君绝 2024-07-19 08:18:14

区别在于哪个父级拥有该对话框。 如果您显式设置父窗口,则该窗口拥有该对话框。 如果您没有设置它(使用 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.

趁微风不噪 2024-07-19 08:18:14

它确实有所不同...

我有一个调用 ShowDialog(Me) 的 MDI 子项,在生成的对话框窗口中,Me.Owner 引用 MDI 容器,而不是 MDI 子项。

使用 Me.Owner.ActiveControl 是一种解决方法,但使用:

       Dim ContractForm As New Contract(strType, intMode)
       ContractForm.Owner = Me
       dgrAction = ContractForm.ShowDialog()

可以很好地获取它。 在生成的对话框窗口中,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:

       Dim ContractForm As New Contract(strType, intMode)
       ContractForm.Owner = Me
       dgrAction = ContractForm.ShowDialog()

Gets it nicely. In the resulting dialog window, Me.Owner now does reference the MDI child.

Hope this helps!

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