How do you know if Windows Form is open, but behind a different window?

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

I want to know how to determine if a form is open, but “hidden” behind another application window.

If this is the case, I want to bring it to the forefront and actually make it visible to the user.

I tried the BringToFront () method, but that did not work. I also tried calling the Show () method, but if the form is behind another application window, it remains so.

The only workaround I found in this problem is setting the FormWindowState form to Minimized / Maximized and then to a normal one, but a bit hacked and doesn't look pretty.

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

+5
source share
3 answers

It’s strange.

this.Activate() gotta do the trick.

You can always try the “terrible hacking method” that I find guilty of distribution. But if it this.Activate()doesn’t work, for testing you can try:

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

I have never seen this recommended as a solution, but it can show you the functionality. I am more worried about why it this.Activate()doesn’t work if the above code takes place.

, #, . : , Windows Forms?

+6

,

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

, , , / .

+1

, , Focus. , , . Focused. , , , , .
"" , "" Focus().

Note. The window may be focused and located under another window.
To determine if your window is under another window, I am afraid that you should go deeper.

-1
source

All Articles