如何把鼠标控制在form之内。谢谢!

lbsoftware 2003-11-21 03:25:06
最好有程序.
thanks!
...全文
82 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
online 2003-11-21
  • 打赏
  • 举报
回复
Option Explicit
' 声明类型
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

Dim Form_Rect As RECT

' 限制鼠标在窗体内活动
Private Sub Form_Load()
With Form_Rect
.Left = Me.Left \ Screen.TwipsPerPixelX
.Top = Me.Top \ Screen.TwipsPerPixelY
.Right = (Me.Left + Me.Width) \ Screen.TwipsPerPixelX
.Bottom = (Me.Top + Me.Height) \ Screen.TwipsPerPixelY
End With
ClipCursor Form_Rect
Release_Btn.Enabled = True
End Sub

' 解除鼠标限制
Private Sub Release_Btn_Click()
ClipCursor Form_Rect
Release_Btn.Enabled = False
End Sub

' 退出之前确保解除鼠标限制
Private Sub Exit_Btn_Click()
If Release_Btn.Enabled = True Then
' Release_Btn_Click
End If
End
End Sub

3661512 2003-11-21
  • 打赏
  • 举报
回复
Option Explicit
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 Form_Load()
Dim rscreen As RECT
rscreen.Top = Form1.Top
rscreen.Left = Form1.Left
rscreen.Right = Form1.Width
rscreen.Bottom = Form1.Height
ClipCursor rscreen
End Sub

7,732

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧