Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / March 2006

Tip: Looking for answers? Try searching our database.

How to Determine if Windows Form is hidden?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JD - 28 Mar 2006 12:41 GMT
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
Mehdi - 28 Mar 2006 12:55 GMT
> 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.
JD - 28 Mar 2006 13:06 GMT
Thanks Mehdi.

> > At run time I want to know if my form is "hidden" behind another window.
> >
[quoted text clipped - 19 lines]
> your window is visible to the user or not. But there might be an API for
> that as well.
Jason Hales - 28 Mar 2006 16:19 GMT
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
Cerebrus - 28 Mar 2006 19:03 GMT
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.
Jason Hales - 29 Mar 2006 11:12 GMT
>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
Cerebrus - 29 Mar 2006 21:15 GMT
Ok, cool, I think I understand the difference now !

Thanks, Jason,

Regards,

Cerebrus.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.