在一個窗體裡面,如何控製鼠標只能在窗體裡面移動.

解决方案 »

  1.   

    Option Explicit
    Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End TypePrivate Sub Command1_Click()
    Dim r As RECT
    Timer1.Enabled = False
    r.Left = 0
    r.Top = 0
    r.Bottom = Screen.Height
    r.Right = Screen.Width
    ClipCursor r
    End SubPrivate Sub Form_Load()
    Timer1.Interval = 1
    Command1.Caption = "恢复"
    End SubPrivate Sub Timer1_Timer()
    Dim r As RECT
    GetWindowRect Me.hwnd, r
    ClipCursor rEnd Sub
      

  2.   

    If X > Me.Width Or Y < Me.Height Then
       MDI窗体或者其它窗体.Enabled = False
    End If