SKProCH
SKProCH

Reputation: 191

Best way to determine if a user can view a window

How can I determine if a user can see a window (fully or partially) at the screen using WPF/C#?

I tried to define this using WindowState, but the window may be “under” other windows.


For example now the window are focused and user can view it:

Fully visible window


Now part of window are covered with IDE, but user still can view it:

Partially visible window


Now the window is completely covered by the IDE window, and the user cannot see it.

No visible window


How can I now determine in what "visible state" the window is?

Upvotes: 0

Views: 480

Answers (2)

Kux
Kux

Reputation: 1489

You could do a "hit test" on the 4 corners coordinates and if all tests return your window then the window is completely visible.

  • see also: VisualTreeHelper.HitTest function
  • see also: WindowFromPoint function (user32.dll)

Upvotes: 1

Sargis Tovmasyan
Sargis Tovmasyan

Reputation: 113

You can track when your application active(or focused) but I am not sure is it possible with a partially visible window, in any case, read this, hope it will be helpful.

Upvotes: 0

Related Questions