Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleConfine the cursor within a form's client area
Keywordsconfine, cursor, clip, client area
CategoriesTips 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated