vb 如何点击某按钮,鼠标移动到窗体内某位置?
例如在text1、text2中分别输入x、y坐标。单击按钮然后鼠标指针移动到相应的窗体内的位置?我找了代码OptionExplicitPrivateDeclareFunc...
例如在text1、text2中分别输入x、y坐标。单击按钮然后鼠标指针移动到相应的窗体内的位置?我找了代码
Option Explicit
Private Declare Function SetCursorPos Lib "user32" ( _
ByVal x As Long, _
ByVal y As Long _
) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Sub Command1_Click()
SetCursorPos Text1.Text , Text2.Text
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
但是用了一下发现他移动到了屏幕上对应的坐标。现在怎么写一段代码,让他点击时移动到窗体内相应的位置? 展开
Option Explicit
Private Declare Function SetCursorPos Lib "user32" ( _
ByVal x As Long, _
ByVal y As Long _
) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Sub Command1_Click()
SetCursorPos Text1.Text , Text2.Text
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
但是用了一下发现他移动到了屏幕上对应的坐标。现在怎么写一段代码,让他点击时移动到窗体内相应的位置? 展开
3个回答
展开全部
如果不嫌麻烦的话,可以这样:
1、读取窗体内部宽度W1、高度H1。
2、获取当前屏幕分辨率Xp、Yp。
3、读取需要跳转的X、Y坐标。
4、X1=(W1/Xp)*x
5、求的Y1
6、执行光标设置命令,就可以设置到你窗体的指定位置了
1、读取窗体内部宽度W1、高度H1。
2、获取当前屏幕分辨率Xp、Yp。
3、读取需要跳转的X、Y坐标。
4、X1=(W1/Xp)*x
5、求的Y1
6、执行光标设置命令,就可以设置到你窗体的指定位置了
更多追问追答
追问
还是谢谢你为我提供思路!但我想要具体源码。。
追答
Private Sub Command1_Click()
SetCursorPos Text1.Text +Me.left\15, Text2.Text+me.top\15
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
Text2.Text+me.top\15中的15是固定比列,就是me.top\15得到的就是屏幕分辨率,比如为1024.
如果要适应所有屏幕分辨率的话,就要用我告诉你的方法算出来,而不是固定比例。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Private Declare Function SetCursorPos Lib "user32" ( _
ByVal x As Long, _
ByVal y As Long _
) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Sub Command1_Click()
SetCursorPos Text1.Text +Me.left\15, Text2.Text+me.top\15
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
Private Declare Function SetCursorPos Lib "user32" ( _
ByVal x As Long, _
ByVal y As Long _
) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Sub Command1_Click()
SetCursorPos Text1.Text +Me.left\15, Text2.Text+me.top\15
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我不知道写代码,不过用录制的办法,又快又好啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询