您的位置首页百科问答

如何将鼠标控制在窗体之类,无法移到窗体之外去。VB6.0

如何将鼠标控制在窗体之类,无法移到窗体之外去。VB6.0

把Form的Moveable设为False,Borderstyle设为1.代码如下。==========亩喊===========Option ExplicitDim R As RECTPrivate Type RECT Left As Long Top As Long Right As Long Bottom As LongEnd TypePrivate 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 LongPrivate Sub Form_Load() '窗体载入后,鼠标只能在窗体范围内移动SetRect R, Left / Screen.TwipsPerPixelX + 3, Top / Screen.TwipsPerPixelY + 3, (Left + Width) / Screen.TwipsPerPixelX - 3, (Top + Height) / Screen.TwipsPerPixelY - 3ClipCursor REnd SubPrivate Sub Form_Unload(Cancel As Integer) '窗体退出时,取消鼠标光标限制范围ClipCursorByNum 0End Sub