I have a Mouse Move method that moves a Button up and down along the Y axis on a WinForms project
When the Cursor is outside the bounds of the form the Button will not move
I would like to limit the Cursor from exiting or losing focus of the form
I would also like to set a limit on the top and bottom Y positions of the Button btnPad
Other Controls on the form are three buttons that form a TOP, BOTTOM and RIGHT WALL
The Y INSIDE dimensions of the TOP and BOTTOM walls are 50 and 690
FWIW the Form dimensions are Width 1000 and Height 890
I have some code that prevents the cursor from entering the form called MoveCursor
I will post some code I have tried like frmStart MouseLeave and MouseEnter as well as the actual MouseMove code
The Question is how to prevent the Cursor from exiting the Form?
Private Sub MoveCursor()
' Set the Current cursor, move the cursor's Position,
' and set its clipping rectangle to the form.
Me.Cursor = New Cursor(Cursor.Current.Handle)
Cursor.Position = New Point((Cursor.Position.X + 1000), (Cursor.Position.Y + 890))
Cursor.Clip = Me.Bounds
Cursor.Clip = New Rectangle(Me.Location, Me.Size)
End Sub
Private Sub frmStart_MouseLeave(ByVal sender As Object, ByVal e As EventArgs)
Cursor.Position = New Point(X, Y)
Cursor.Clip = Me.Bounds
End Sub
Private Sub frmStart_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
MoveCursor()
btnPad.Top = e.Y
End Sub
The code below was as close as I could come to keeping the Cursor inside the play area which is the form the mouse still wanders out on the right side
Private Sub frmStart_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
Cursor.Clip = New Rectangle(Me.Location, Me.Size)
btnPad.Top = e.Y
End Sub