Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Form is in bounds of all screens

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.

like image 516
Marvin Dickhaus Avatar asked Jan 17 '13 16:01

Marvin Dickhaus


1 Answers

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
like image 108
SysDragon Avatar answered Nov 15 '22 10:11

SysDragon