vb中如何不让鼠标离开窗体(vb6.0的)
来源:百度知道 编辑:UC知道 时间:2024/06/25 05:17:19
ALT怎么用?能说的明白点么?我刚学VB,不明白的.谢谢啦....
把Form的Moveable设为False,Borderstyle设为1.代码如下。
=====================
Option Explicit
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 + 3, Top / Screen.TwipsPerPixelY + 3, (Left + Width) / Screen.TwipsPerPixelX - 3, (Top + Height) / Screen.TwipsPerPixelY - 3
ClipCursor R
End Sub
Private Sub Form_Unload(Cancel As Integer)