How to Determine if Windows Form is hidden?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

At run time I want to know if my form is "hidden" behind another window.

The "Visible" property of the form returns true even when the form is NOT
Visible!

My application updates the form at intervals - I only want this to occur if
the user can actually see the form.

Anyone know how I can achieve this?

Thanks,
J
 
At run time I want to know if my form is "hidden" behind another window.

The "Visible" property of the form returns true even when the form is NOT
Visible!

Yes, it is technically visible in the sense that the user can show it by
clicking on its title in the task bar of by moving the other windows
around. A hidden window is a window that is really invisible to the user
and that the user can not see whatever they do.
My application updates the form at intervals - I only want this to occur if
the user can actually see the form.

Anyone know how I can achieve this?

No easy way to do that i'm afraid. As a starting point, i would suggest you
to look at the APIs in the user32 lib (you'll need to do some interop to
access those APIs). You should be able to retrieve the list of all current
windows, which should allow to retrieve their current visible state as well
as their size and location. What i don't know though is how you could get
the Z-order of the currently visible windows in order to determine whether
your window is visible to the user or not. But there might be an API for
that as well.
 
Thanks Mehdi.



Mehdi said:
Yes, it is technically visible in the sense that the user can show it by
clicking on its title in the task bar of by moving the other windows
around. A hidden window is a window that is really invisible to the user
and that the user can not see whatever they do.


No easy way to do that i'm afraid. As a starting point, i would suggest you
to look at the APIs in the user32 lib (you'll need to do some interop to
access those APIs). You should be able to retrieve the list of all current
windows, which should allow to retrieve their current visible state as well
as their size and location. What i don't know though is how you could get
the Z-order of the currently visible windows in order to determine whether
your window is visible to the user or not. But there might be an API for
that as well.
 
There is a saimple way if you don't mind trapping your form's Paint
event by looking at the ClipRectangle:

private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
string now = DateTime.Now.ToString("hh:mm:ss");

if (e.ClipRectangle.Width > 0 || e.ClipRectangle.Height > 0)
{

this.Text = now;
Debug.WriteLine("Partially visible" + now);
}

}

This code updates the form's caption if any part needs redrawing and
hence is visible
 
Hi,

Guys, please forgive my ignorance, but is it not possible to use the
Form.ActiveForm property in this case ?

As in :
---------------------------------------
Dim myForm as Form = Form.ActiveForm
If myForm is Me Then

' Update the form at intervals

End if
---------------------------------------
Something like that ??

Regards,

Cerebrus.
 
is it not possible to use the Form.ActiveForm property in this case ?
Yes, good point, ActiveForm will return a reference to the ACTIVE form
in the CURRENT application but it won't help if you need to know if
that active form is obscured by windows from other applications that
are running
 
Back
Top