How do you tell if a Windows Form is open but behind another window?

点点圈 提交于 2019-12-05 09:38:30
JClaspill

Strange.

this.Activate() should do the trick.

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;

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.

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?

Try to wire below,

private void frmMyForm_Deactivate(object sender, EventArgs e)
    {
        // Raise your flag here.
    }

By wiring above event, it will tell you whenever the form is minimized, partially/totally hided by another form.

Well, as you know, windows might or might not have Focus. If a windows is focused, it is therefore that the user have clicked it. You can try the Focused property. Otherwise, I don't think there is a property which tells you if another window is above yours.
You can "give" focus, therefore "popping out" the window with the Focus() method.

Note: A window can be both focused and be under another window.
To determine if your window isn't under another window, I'm afraid you must go deeper.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!