I'm trying to elaborate if the complete form is visible on screen. To clarify this: I don't care if the form is partially or fully hidden by another form, I just want to know, if the form is completely on the screen.
In Windows it is possible to move forms around, such that they are hidden half way. That is because you can move them past the actual bounds of any monitor. (Further to the left, right or bottom.) How can I check if that is the case in an easy way?
What I figured I could do is to check if the form is in bounds of SystemInformation.VirtualScreen
. The problem here is, that not every pixel of the virtual screen is actually visible. Of course this would work if SystemInformation.MonitorCount = 1
Still I'm not really happy with this.
Public Function IsOnScreen(ByVal form As Form) As Boolean
Dim screens() As Screen = Screen.AllScreens
For Each scrn As Screen In screens
Dim formRectangle As Rectangle = New Rectangle(form.Left, form.Top, form.Width, form.Height)
If scrn.WorkingArea.Contains(formRectangle) Then
Return True
End If
Next
Return False
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With