-
vb教程之鼠标编程小技巧二则
作者:土人
一.通过鼠标在屏幕上的移动来控件程序界面
本例通过鼠标在屏幕上的移动来控制程序窗体的显示与隐藏:当鼠标移动到窗体所在区域时窗体显示,反之隐藏起来。仅需一条API函数:GetCursorPos。注意:如果需要将API函数置于模块中请对代码作相应修改。要尝试本例,需给标准EXE工程缺省添加一个Timer控件。
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Form_Load()
Me.Visible = False
Timer1.Enabled = True
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Dim lResult As Long
Dim lpPoint As POINTAPI
Dim iCounter As Integer
lResult = GetCursorPos(lpPoint)
If lpPoint.x < Me.Left \ Screen.TwipsPerPixelX Or lpPoint.x > (Me.Left + _
Me.Width) \ Screen.TwipsPerPixelX Or lpPoint.y < Me.Top \ _
Screen.TwipsPerPixelY Or lpPoint.y - 10 > (Me.Top + Me.Height) \ _
Screen.TwipsPerPixelY Then
Me.Visible = False '鼠标在窗体区域之外时
Else
Me.Visible = True '鼠标在窗体区域之内时
End If
End Sub
二.获得Mouse_Exit事件
所谓Mouse_Exit事件,是指鼠标指针离开某一控件所应发生的事件。本例是通过Form_MouseMove事件来判断鼠标指针是在窗体之内还是窗体之外的,你可根据需要作相应改动。请给窗体缺省创建一个按钮(用于观察效果)。
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MouseExit As Boolean
MouseExit = (0 <= X) And (X <= Me.Width) And (0 <= Y) And (Y <= Me.Height)
If MouseExit Then
Me.Caption = "鼠标指针在窗体范围内"
Command1.Enabled = True
SetCapture Me.hWnd
Else
Me.Caption = "鼠标指针在窗体范围外"
Command1.Enabled = False
ReleaseCapture
End If
End Sub
一.通过鼠标在屏幕上的移动来控件程序界面
本例通过鼠标在屏幕上的移动来控制程序窗体的显示与隐藏:当鼠标移动到窗体所在区域时窗体显示,反之隐藏起来。仅需一条API函数:GetCursorPos。注意:如果需要将API函数置于模块中请对代码作相应修改。要尝试本例,需给标准EXE工程缺省添加一个Timer控件。
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Form_Load()
Me.Visible = False
Timer1.Enabled = True
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Dim lResult As Long
Dim lpPoint As POINTAPI
Dim iCounter As Integer
lResult = GetCursorPos(lpPoint)
If lpPoint.x < Me.Left \ Screen.TwipsPerPixelX Or lpPoint.x > (Me.Left + _
Me.Width) \ Screen.TwipsPerPixelX Or lpPoint.y < Me.Top \ _
Screen.TwipsPerPixelY Or lpPoint.y - 10 > (Me.Top + Me.Height) \ _
Screen.TwipsPerPixelY Then
Me.Visible = False '鼠标在窗体区域之外时
Else
Me.Visible = True '鼠标在窗体区域之内时
End If
End Sub
二.获得Mouse_Exit事件
所谓Mouse_Exit事件,是指鼠标指针离开某一控件所应发生的事件。本例是通过Form_MouseMove事件来判断鼠标指针是在窗体之内还是窗体之外的,你可根据需要作相应改动。请给窗体缺省创建一个按钮(用于观察效果)。
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MouseExit As Boolean
MouseExit = (0 <= X) And (X <= Me.Width) And (0 <= Y) And (Y <= Me.Height)
If MouseExit Then
Me.Caption = "鼠标指针在窗体范围内"
Command1.Enabled = True
SetCapture Me.hWnd
Else
Me.Caption = "鼠标指针在窗体范围外"
Command1.Enabled = False
ReleaseCapture
End If
End Sub
最新更新
求1000阶乘的结果末尾有多少个0
详解MyBatis延迟加载是如何实现的
IDEA 控制台中文乱码4种解决方案
SpringBoot中版本兼容性处理的实现示例
Spring的IOC解决程序耦合的实现
详解Spring多数据源如何切换
Java报错:UnsupportedOperationException in Col
使用Spring Batch实现批处理任务的详细教程
java中怎么将多个音频文件拼接合成一个
SpringBoot整合ES多个精确值查询 terms功能实
数据库审计与智能监控:从日志分析到异
SQL Server 中的数据类型隐式转换问题
SQL Server中T-SQL 数据类型转换详解
sqlserver 数据类型转换小实验
SQL Server数据类型转换方法
SQL Server 2017无法连接到服务器的问题解决
SQLServer地址搜索性能优化
Sql Server查询性能优化之不可小觑的书签查
SQL Server数据库的高性能优化经验总结
SQL SERVER性能优化综述(很好的总结,不要错
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比