How to test if a control is visible on screen

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

Guest

Hallo experts

How can I test if a control is currently visible on screen and not hidden by
other windows?
 
How can I test if a control is currently visible on screen and not hidden by
other windows?

I'm unaware of any easy API call to do this (perhaps there is a User32
function?). In lieu of an easy solution, you could try a more brute-force
method:

1. Get an array of all open windows. (You can use the User32 EnumWindows
function and Interop to get this.)
2. Iterate through the array. Every window in the array before your window
is higher in the Z-order, i.e., can potentially cover the control in your
window.
3. Find the screen coordinates of your control. You can find the upper
left-corner with the control.PointToScreen( new Point(0,0) ) method.
4. Ensure that none of the higher-Z-order windows cover the control's
screen coordinates.
 
Back
Top