VB 鼠标控制

 我来答
衷贤迟丑
2020-02-19 · TA获得超过3.6万个赞
知道大有可为答主
回答量:1.4万
采纳率:33%
帮助的人:839万
展开全部
form1添加两个command控件和一个timer控件,添加如下代码:
Dim
moulast
As
POINTAPI
Dim
moubegin
As
POINTAPI
Dim
MoveCount
As
Integer
Dim
mousestep
As
POINTAPI
Private
Sub
Command1_MouseUp(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)

MsgBox
("你按下了Command1键")

Timer1.Enabled
=
False
End
Sub
Private
Sub
Command2_Click()

Dim
destrect
As
RECT

'获得Command1在屏幕上的坐标。

GetWindowRect
Command1.hwnd,
destrect

'获得要移动到的位置的光标的坐标。

moulast.X
=
destrect.Left

moulast.Y
=
destrect.Top

'获得当前光标的坐标。

GetCursorPos
moubegin

Timer1.Enabled
=
True

stepx
=
moulast.X
-
moubegin.X

stepy
=
moulast.Y
-
moubegin.Y

mousestep
=
moubegin
End
Sub
Private
Sub
Timer1_Timer()

mousestep.X
=
mousestep.X
+
15

mousestep.Y
=
mousestep.Y
+
10

SetCursorPos
mousestep.X,
mousestep.Y

If
mousestep.X
>
moulast.X
And
mousestep.Y
>
moulast.Y
Then

Timer1.Enabled
=
False

SendMessage
Command1.hwnd,
WM_LBUTTONUP,
10,
10

End
If
End
Sub
Module1代码:
Public
Type
RECT

Left
As
Long

Top
As
Long

Right
As
Long

Bottom
As
Long
End
Type
Public
Type
POINTAPI

X
As
Long

Y
As
Long
End
Type
Public
Const
WM_LBUTTONUP
=
&H202
Public
Declare
Function
GetWindowRect
Lib
"user32"
(ByVal
hwnd
As
Long,
lpRect
As
RECT)
As
Long
Public
Declare
Function
SetCursorPos
Lib
"user32"
(ByVal
X
As
Long,
ByVal
Y
As
Long)
As
Long
Public
Declare
Function
GetCursorPos
Lib
"user32"
(lpPoint
As
POINTAPI)
As
Long
Public
Declare
Function
SendMessage
Lib
"user32"
Alias
"SendMessageA"
(ByVal
hwnd
As
Long,
ByVal
wMsg
As
Long,
ByVal
wParam
As
Long,
lParam
As
Any)
As
Long
武义菲亚伏电子有限公司
2023-06-12 广告
绝缘子控件是指:“一种能够在架空输电线路中起到重要作用的特殊绝缘控件,能够在架空输电线路中起到重要作用。”绝缘子的作用是支持和固定母线与带电导体,并使带电导体间或导体与大地之间有足够的距离和绝缘。绝缘子应具有足够的电气绝缘强度和耐潮湿性能。... 点击进入详情页
本回答由武义菲亚伏电子有限公司提供
督秀珍安念
2020-01-25 · TA获得超过3.6万个赞
知道大有可为答主
回答量:1.2万
采纳率:26%
帮助的人:1001万
展开全部
你是希望调用command的click事件吧
没必要这么麻烦的,
当你需要点击command时
只需写上
command1_click
就可以了,相当于是调用事件
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式