C# - 如何处理 2 个“TopMost”表格?

发布于 2024-08-08 13:05:30 字数 283 浏览 4 评论 0原文

我有一个设置为 TopMost 的父表单,然后我有另一个在单击按钮时打开的表单。该子窗体也设置为 TopMost。我遇到的第一个问题是,当我打开子表单时,应用程序基本上会冻结,因为您无法访问任何内容。我决定不使用 ShowDialog() 打开子窗体,而是使用 Show(this)。这确实解决了最初的问题,但现在我有了一个新问题。子窗体起始位置设置为 CenterParent,当我使用 Show(this) 时,它不起作用。有什么方法可以让子窗体打开,同时将子窗体和父窗体都设置为最顶层,同时将子窗体起始位置设置为 CenterParent?谢谢。

I have a parent form that is set to be TopMost and then I have another form that opens when a button is clicked. This child form is also set to be TopMost. The first issue I had was that when I opened the child form, the application would basically freeze because you couldn't access anything. I decided that instead of using ShowDialog() to open the child form, I would use Show(this). This did fix the initial problem but now I have a new one. The childforms start postition is set to be CenterParent and when I use Show(this), it doesn't work. Is there any way I can make the childform open while both it and the parent form are set to topmost while having the childforms start position set to CenterParent? Thank you.

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

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

发布评论

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

评论(3

云淡风轻 2024-08-15 13:05:30

我发现了一些有用的东西可以与你们分享。相反,以下代码

form2.TopMost = true;

在主窗体中使用此代码:

form2.Owner = this;

如果您使用 Form.TopMost 属性,则该窗体将覆盖所有其他非最顶层窗体,以及来自其他应用程序的窗体。取而代之的是,将 Form.Owner 属性设置为父窗体 - 应该位于窗体下的窗体(例如主窗体)。
运气真好:)

I've find something useful to share with you, guys. Instead following code

form2.TopMost = true;

use this code in main form:

form2.Owner = this;

If you use Form.TopMost property, the form will overlap all other non-topmost forms, but also those from other applications. Instead of this, set the Form.Owner property to the parent form – the one which should be under the form (e.g. the main form).
G00d luck :)

不乱于心 2024-08-15 13:05:30

您可以尝试在子窗体可见期间清除父窗体的 TopMost 属性。

这将解决哪种形式应该位于最顶层的问题,因为永远只有一种形式。

You could try clearing the TopMost property of the parent form for the duration that the child form is visible.

This would solve the problem of which form should be top most, as there will only ever be one.

一梦浮鱼 2024-08-15 13:05:30

唔。我已经创建了“收件人”表单。然后我在两者上设置 TopMost = true 。我将按钮添加到第一个并写道
new Form2().ShowDialog();

一切都很好。 Form2 处于活动状态且可点击。 Form1 自从 ShowDialog 被调用后就没有了

,第二个变体工作正常。 Form2 在屏幕中央打开。

也许我误解了什么?

Hmm. I've created To forms. Then i set TopMost = true on both. The i add button to first and wrote
new Form2().ShowDialog();

And all just fine. Form2 active and clickable. Form1 not since ShowDialog was called

And second variant works fine. Form2 opened in center of the screen.

May be i misunderstood something?

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