VB鼠标移动事件 20
用菜单编辑器做了个菜单,“文件”为主菜单,其下有一子菜单“保存”请问如何写代码实现鼠标指针移动到“文件”上子菜单自动下拉?是移动,非点击也。...
用菜单编辑器做了个菜单,“文件”为主菜单,其下有一子菜单“保存” 请问如何写代码实现鼠标指针移动到“文件”上子菜单自动下拉?是移动,非点击也。
展开
7个回答
展开全部
来的晚,帮顶顶,楼上代码很好,很强大.嘿嘿`~!!
不过有点局限,mousemove事件只局限在form中.
建议通过GetCursorPos
API来获取鼠标坐标.
从而判断,鼠标是否移动
呵呵,根据你要求写了下面代码,你试试
Private
Declare
Function
GetCursorPos
Lib
"user32"
(lpPoint
As
POINTAPI)
As
Long
Private
Type
POINTAPI
x
As
Long
y
As
Long
End
Type
Dim
NowPos
As
POINTAPI
'用来纪录鼠标停止时坐标
Const
HandleTime
=
20
'20分钟后处理
Dim
NowCount
As
Integer
'用来纪录鼠标停止了多久
Private
Sub
Form_Load()
Timer1.Interval
=
1000
'1秒检测一次
Timer1.Enabled
=
True
Timer2.Interval
=
60000
'1分钟一次
timer时间
Timer2.Enabled
=
False
GetCursorPos
NowPos
NowCount
=
0
End
Sub
Private
Sub
Timer1_Timer()
Dim
tmpPos
As
POINTAPI
GetCursorPos
tmpPos
If
tmpPos.x
=
NowPos.x
And
tmpPos.y
=
NowPos.y
Then
If
Not
Timer2.Enabled
Then
Timer2.Enabled
=
True
Else
Timer2.Enabled
=
False
NowCount
=
0
End
If
NowPos
=
tmpPos
Me.Caption
=
"当前鼠标坐标是:"
&
NowPos.x
&
","
&
NowPos.y
&
"鼠标已经静止了"
&
NowCount
&
"分钟了哦"
End
Sub
Private
Sub
Timer2_Timer()
NowCount
=
NowCount
+
1
If
NowCount
=
HandleTime
Then
MsgBox
"你已经20分钟没动过了哦,退出我吗
?"
End
Sub
不过有点局限,mousemove事件只局限在form中.
建议通过GetCursorPos
API来获取鼠标坐标.
从而判断,鼠标是否移动
呵呵,根据你要求写了下面代码,你试试
Private
Declare
Function
GetCursorPos
Lib
"user32"
(lpPoint
As
POINTAPI)
As
Long
Private
Type
POINTAPI
x
As
Long
y
As
Long
End
Type
Dim
NowPos
As
POINTAPI
'用来纪录鼠标停止时坐标
Const
HandleTime
=
20
'20分钟后处理
Dim
NowCount
As
Integer
'用来纪录鼠标停止了多久
Private
Sub
Form_Load()
Timer1.Interval
=
1000
'1秒检测一次
Timer1.Enabled
=
True
Timer2.Interval
=
60000
'1分钟一次
timer时间
Timer2.Enabled
=
False
GetCursorPos
NowPos
NowCount
=
0
End
Sub
Private
Sub
Timer1_Timer()
Dim
tmpPos
As
POINTAPI
GetCursorPos
tmpPos
If
tmpPos.x
=
NowPos.x
And
tmpPos.y
=
NowPos.y
Then
If
Not
Timer2.Enabled
Then
Timer2.Enabled
=
True
Else
Timer2.Enabled
=
False
NowCount
=
0
End
If
NowPos
=
tmpPos
Me.Caption
=
"当前鼠标坐标是:"
&
NowPos.x
&
","
&
NowPos.y
&
"鼠标已经静止了"
&
NowCount
&
"分钟了哦"
End
Sub
Private
Sub
Timer2_Timer()
NowCount
=
NowCount
+
1
If
NowCount
=
HandleTime
Then
MsgBox
"你已经20分钟没动过了哦,退出我吗
?"
End
Sub
展开全部
菜单在窗体中的位置相对是固定的(一定固定那里的吧),所以,你可以在鼠标移动的时候获得获得鼠标随时移动的坐标,同时获得菜单的坐标,两个坐标有交点的时候,即鼠标进入了菜单的区域,你就让他触发一个打开这个菜单的函数。我是空想的,你可以试试,不行再说,因为VB菜单确实不支持那些鼠标动作
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option
Explicit
Private
mChkMin
As
Long
Private
mTmrCount
As
Long
Private
Sub
Form_Load()
Timer1.Interval
=
60000
'1
min
Timer1.Enabled
=
True
mChkMin
=
20
'
End
Sub
Private
Sub
Form_MouseMove(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
mTmrCount
=
0
'reset
count
to
0
End
Sub
'
'当关闭系统的时候点击右上角的小X
就直接退出系统了
'能不能写段代码
当点击小X(关闭按钮)的时候弹'出提示筐
确认是否关闭系统??
Private
Sub
Form_Unload(Cancel
As
Integer)
dim
ret
as
long
ret
=
MsgBox("
是否退出系统
?",
vbYesNo
+
vbInformation)
If
ret
=
vbNo
Then
Cancel
=
True
End
If
End
Sub
Private
Sub
Timer1_Timer()
mTmrCount
=
mTmrCount
+
1
Dim
ret
As
Long
If
mTmrCount
>=
mChkMin
Then
ret
=
MsgBox("已经"
&
mChkMin
&
"分钟无任何造作,是否退出系统",
vbYesNo
+
vbInformation)
If
ret
=
vbYes
Then
End
End
If
mTmrCount
=
0
End
If
End
Sub
Explicit
Private
mChkMin
As
Long
Private
mTmrCount
As
Long
Private
Sub
Form_Load()
Timer1.Interval
=
60000
'1
min
Timer1.Enabled
=
True
mChkMin
=
20
'
End
Sub
Private
Sub
Form_MouseMove(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
mTmrCount
=
0
'reset
count
to
0
End
Sub
'
'当关闭系统的时候点击右上角的小X
就直接退出系统了
'能不能写段代码
当点击小X(关闭按钮)的时候弹'出提示筐
确认是否关闭系统??
Private
Sub
Form_Unload(Cancel
As
Integer)
dim
ret
as
long
ret
=
MsgBox("
是否退出系统
?",
vbYesNo
+
vbInformation)
If
ret
=
vbNo
Then
Cancel
=
True
End
If
End
Sub
Private
Sub
Timer1_Timer()
mTmrCount
=
mTmrCount
+
1
Dim
ret
As
Long
If
mTmrCount
>=
mChkMin
Then
ret
=
MsgBox("已经"
&
mChkMin
&
"分钟无任何造作,是否退出系统",
vbYesNo
+
vbInformation)
If
ret
=
vbYes
Then
End
End
If
mTmrCount
=
0
End
If
End
Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没办法,VB中菜单不接受MouseUp等动作。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
似乎可以用mousemove事件来做
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询