.ShowDialog() 无法显示 MDI 子窗口 为什么?

发布于 2024-09-09 05:22:00 字数 183 浏览 2 评论 0原文

我使用 winforms MDI 窗口并在其上显示子窗口。 我需要使用模态对话框模式( .ShowDialog() )显示其中一些,但仍然将它们显示为子窗口(它们应该保留在父窗口的边框内)。

当我尝试执行此操作时,出现编译时错误,指出子窗口无法显示为模式对话框模式窗口。

有什么办法可以做到吗?

I use winforms MDI window and display child windows on it.
I need to display some of them using modal dialog mode ( .ShowDialog() ) but still have them displayed as a child window (they should stay within the borders of the parent windows).

When I try to do this I get a compile time error saying that the child window cannot be displayed as a modal dialog mode window.

Is there any way to do it?

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

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

发布评论

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

评论(3

甜嗑 2024-09-16 05:22:00

我认为没有直接的方法可以做到这一点。但是,在低级别上,模式对话框是通过禁用父窗口来实现的。尝试显示无模式 MDI 子项并保持父项禁用,除非该子项已关闭。

I don't think that there is direct way to do this. However, on the low level modal dialogs are implemented by disabling a parent window. Try to show modeless MDI child and keep parent disabled unless this child is closed.

方觉久 2024-09-16 05:22:00

我通常会通过使子窗体上的所有控件成为用户控件的一部分,然后将用户控件添加到子窗体并创建一个也包含用户控件的单独对话框来解决此问题。这意味着您可以重用几乎所有代码,并且通常有一些代码无论如何都会有所不同(子窗体通常没有“确定”/“取消”按钮等)。

但是,如果您不想走这条路,这里有一篇 codeproject 文章,据说有解决方法(我没有仔细查看): MDI 子项作为对话框表单(MDI 模式解决方法)

I'd normally get around this by making all the controls on the childform be part of a user control and then add the user control to the childform and make a separate dialog also containing the user control. That means that you can reuse almost all the code and there's usually some code that will be different anyway (the childform normally doesn't have OK/Cancel buttons etc).

However, if you don't want to go down that route here's a codeproject article that supposedly has a workaround (I've not looked at it carefully): MDI child as dialog form (MDI modal workaround)

拒绝两难 2024-09-16 05:22:00

如果您希望模态窗口在父窗体的范围内打开,只需将窗体属性 StartPosition 设置为 CenterParent 即可。

If you want the modal window to simply open up within the bounds of the parent form, just set the form property StartPosition to CenterParent.

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