|  |  | 
              
              | 
                  | Title | Confine the cursor within a form's client area | 
|---|
 | Keywords | confine, cursor, clip, client area | 
|---|
 | Categories | Tips and Tricks, API | 
|---|
 |  | 
 |  | Use the ClientToScreen API function to translate the form client area's position into screen coordinates. Then use the ClipCursor function to restrict the cursor to that area. |  | 
 |  
                | Private Sub Check1_Click()
Dim r As RECT
Dim p As POINTAPI
    If Check1.Value = vbChecked Then
        p.x = 0
        p.y = 0
        ClientToScreen hwnd, p
        r.Left = p.x
        r.Top = p.y
        p.x = ScaleWidth
        p.y = ScaleHeight
        ClientToScreen hwnd, p
        r.Right = p.x
        r.Bottom = p.y
        MousePointer = vbHourglass
        ClipCursor r
    Else
        MousePointer = vbDefault
        ClipCursor ByVal 0& ' vbNull
    End If
End Sub |  |  |  |   |  |  |  |  |