<pre><DllImport("user32")> _ Private Shared Function ClipCursor(ByVal lpRect As RECT) As Int32 End Function <DllImport("user32")> _ Private Shared Function ShowCursor(ByVal bShow As Int32) As Int32 End Function <StructLayout(LayoutKind.Sequential)> _ Private Structure RECT Public Left As Int32 Public Top As Int32 Public Right As Int32 Public Bottom As Int32 End Structure Private MouseTrap As RECT Public Sub RestoreCursor(ByRef ThisForm As System.Windows.Forms.Form) With MouseTrap .Top = 0 .Left = 0 .Right = Screen.PrimaryScreen.Bounds.Width .Bottom = Screen.PrimaryScreen.Bounds.Height End With ClipCursor(MouseTrap) End Sub 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(Me.Left, Me.Top) Cursor.Clip = New Rectangle(Me.Left, Me.Top, Me.Width, Me.Height) ', Me.Size) End Sub Private Sub disableCursor() ShowCursor(False) MoveCursor() End Sub Private Sub enableCursor() RestoreCursor(Me) ShowCursor(True) End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)