您如何判断Windows窗体是否已打开但在另一个窗口后面? [英] How do you tell if a Windows Form is open but behind another window?

查看:205
本文介绍了您如何判断Windows窗体是否已打开但在另一个窗口后面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用Form.Visible将返回true,无论表单是最大化,最小化还是具有FormWindowState为Normal。

Calling Form.Visible will return true regardless of whether the form is maximized, minimized, or has a FormWindowState of Normal.

我想知道的是如何告诉表单是否处于打开状态,但隐藏在另一个应用程序的窗口后面。

What I want to know is how to tell if the form is open but "hidden" behind another application's window.

如果是这种情况,我想将其放在最前面并使之对用户。

If that's the case, I want to bring it to the front and actually make it visible to the user.

我尝试了BringToFront()方法,但是没有用。我还尝试调用Show()方法,但是如果表单位于另一个应用程序窗口的后面,则它仍然保持这种状态。

I tried the BringToFront() method but it didn't work. I also tried calling the Show() method but if the form is behind another application's window, it remains that way.

我发现该问题的唯一解决方法是设置将Form的FormWindowState设置为Minimized / Maximized,然后再正常显示,但这有点麻烦,而且看起来也不好。

The only workaround I found to the problem is setting the Form's FormWindowState to Minimized/Maximized and then normal, but that's a bit of a hack and doesn't look nice.

有人可以告诉我如何判断表单是否正确吗?

Can someone tell me how to tell if the form is behind another window and how to bring it to the front?

推荐答案

奇怪。

this.Activate()应该可以解决问题。

您总是可以尝试骇客方法,我为传播而感到内。但是,如果 this.Activate()不起作用,为了进行测试,您可以尝试:

You can always try a 'horrible hack method', which I feel guilty for spreading. But if this.Activate() doesn't work, for the sake of testing you might try:

this.TopMost = true;
this.Focus();
this.BringToFront();
this.TopMost = false;

我从未见过将其推荐为解决方案,但它可以向您展示其功能。我会更担心为什么 this.Activate()如果上面提到的代码不能正常工作。

I've never seen this recommended as a solution, but it might work to show you the functionality. I'd be more concerned about why this.Activate() isn't working if the above-mentioned code does.

对于检测窗口,不能像这样通过C#使用命令来检测它。查看以下问题的答案以获取更多信息:
如何检查Windows窗体中窗口是否真正可见?

As for detecting the window, you cannot use a command to detect it via C# like that. Check the following questions answers for more info: How to check if window is really visible in Windows Forms?

这篇关于您如何判断Windows窗体是否已打开但在另一个窗口后面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆