发布网友 发布时间:2023-11-13 19:02
共3个回答
热心网友 时间:2024-11-15 20:30
这样: 试试,能不能,我是win7,可以。不过,窗体的边框属性必须为默认 Option Explicit Private Const lBorder As Long = 7 '边框大小,经测试,至少为7才能不出现用户点击窗体边缘导致失效。(可以自己调整,调成100蛮好玩的) Dim R As RECT Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function ClipCursor Lib "user32" (lpRect As RECT) As Long 'lpRect-鼠标光标*到的矩形 Private Declare Function ClipCursorByNum Lib "user32" Alias "ClipCursor" (lpRect As Long) As Long 'lpRect-传0,取消鼠标光标* Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Private Sub Form_Load() '窗体载入后,鼠标只能在窗体范围内移动 SetRect R, Left / Screen.TwipsPerPixelX + lBorder, Top / Screen.TwipsPerPixelY + lBorder, (Left + Width) / Screen.TwipsPerPixelX - lBorder, (Top + Height) / Screen.TwipsPerPixelY - lBorder ClipCursor R End Sub Private Sub Form_Unload(Cancel As Integer) '窗体退出时,取消鼠标光标*范围 ClipCursorByNum 0 End Sub热心网友 时间:2024-11-15 20:31
您也可以通过热心网友 时间:2024-11-15 20:31
这个还不简单吗?以下是代码: Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long Private Sub Command1_Click() Dim r As RECT r.Left = 0: r.Top = 0 r.Right = 320: r.Bottom = 200 ClipCursor End Sub Private Sub Command2_Click() ClipCursor ByVal 0& End Sub