VB 中怎样把鼠标限制在窗体范围内?

来源:百度知道 编辑:UC知道 时间:2024/05/06 06:26:58
VB 中怎样把鼠标限制在窗体范围内?

Option Explicit
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Declare Function ClipCursorBynum& Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim mouse As RECT
Private Sub Command1_Click()

mouse.Left = Me.Left / Screen.TwipsPerPixelX
mouse.Top = Me.Top / Screen.TwipsPerPixelY
mouse.Right = (Me.Left + Me.Width) / Screen.TwipsPerPixelX
mouse.Bottom = (Me.Top + Me.Height) / Screen.TwipsPerPixelY
ClipCursor mouse
End Sub
Private Sub Command2_Click()
ClipCursorBynum 0
End Sub

Private Sub Command3_Click()
ClipCursorBynum 0
Unload Me
End Sub

Private Sub Form_Load()
Command1.Caption = "限制鼠标"
Command2.Caption = "解除限制"
Command3.C