Prevent a Form From Moving Off Screen

Wyko

Member
Joined
Jul 11, 2009
Messages
5
Programming Experience
5-10
Any ideas how to do this smoothly? I want to prevent any part of a form from being dragged beyond the bounds of the screen. Now, the easy way to do that would just be to say:

VB.NET:
        If (Me.Left + Me.Width) > Screen.PrimaryScreen.Bounds.Width Then
            Me.Left = Screen.PrimaryScreen.Bounds.Width - Me.Width
        End If

... and etc for the other sides.

But for whatever reason, that creates some amazingly horrible artifacts on the screen if the user attempts to keep pushing the form to the side. Any ideas?

-Wyko
 
Back
Top