VB怎么移动鼠标到指定位置

VB在窗体的指定位置模拟鼠标单击动作,想知道怎么得到鼠标的坐标,和怎么单击,请高高手完成这种效果的代码::::运行程序后,label1随时显示鼠标的相对于窗体坐标xy.按... VB在窗体的指定位置模拟鼠标单击动作,想知道怎么得到鼠标的坐标,和怎么单击,请高高手完成这种效果的代码::::运行程序后,label1随时显示鼠标的相对于窗体坐标xy.按钮单1击后鼠标自动移动到屏幕的中心位置.并按下按钮2(按钮2在中间,为了证明按钮2按下,请在command2的chick写入 print 123),3Q了,50分先说好,我认为好的话再加50,请将代码尽量写详细说明.
二楼,请解说一下什么是把下面的代码保存为form1.frm?????
展开
 我来答
创作者zUzVB1Sl31
推荐于2016-08-01 · 编程类资料、英语学习资料
创作者zUzVB1Sl31
采纳数:1331 获赞数:5975

向TA提问 私信TA
展开全部

VB光标移动有两种方式:

1. 移动到指定控件,转移焦点:

Text1.SetFocus

2. 移动指定文本字符串位置:

Text1.SelStart=Len(Text1)
ljl88900
推荐于2016-09-24 · TA获得超过2661个赞
知道大有可为答主
回答量:2197
采纳率:100%
帮助的人:2629万
展开全部
把下面代码保存为Form1.frm,然后双击打开此文件,运行即可。
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
Caption = "Form1"
ClientHeight = 4005
ClientLeft = 45
ClientTop = 435
ClientWidth = 6630
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4005
ScaleWidth = 6630
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 495
Left = 2640
TabIndex = 3
Top = 1440
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 4200
TabIndex = 2
Top = 3120
Width = 1215
End
Begin VB.Frame Frame1
BackColor = &H00C0C0C0&
Caption = "鼠标位置"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 840
Left = 120
TabIndex = 0
Top = 3000
Width = 3255
Begin VB.Label Label1
BackColor = &H00C0C0C0&
Caption = "Label1"
Height = 375
Left = 120
TabIndex = 1
Top = 240
Width = 3015
End
End
Begin VB.Timer Timer1
Interval = 10
Left = 720
Top = 960
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type

Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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 Enum MouseClick '定义鼠标常数
MOUSEEVENTF_LEFTDOWN = &H2
MOUSEEVENTF_LEFTUP = &H4
MOUSEEVENTF_RIGHTDOWN = &H8
MOUSEEVENTF_RIGHTUP = &H10
MOUSEEVENTF_MIDDLEDOWN = &H20
MOUSEEVENTF_MIDDLEUP = &H40
End Enum

Private Sub Command1_Click()
Dim pt As POINTAPI
pt.X = Me.ScaleWidth \ Screen.TwipsPerPixelX \ 2
pt.Y = Me.ScaleHeight \ Screen.TwipsPerPixelY \ 2
ClientToScreen Me.hwnd, pt
SetCursorPos pt.X, pt.Y '鼠标自动移动到屏幕的中心位置.
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '自动按下按钮2
End Sub

Private Sub Command2_Click()
Print "123" '按下按钮2后输出字符123
End Sub

Private Sub Form_Load()
With Command2
.Left = (Me.ScaleWidth - .Width) \ 2
.Top = (Me.ScaleHeight - .Height) \ 2
End With
End Sub

Private Sub Timer1_Timer()
Dim pt As POINTAPI
Call GetCursorPos(pt)
ScreenToClient Me.hwnd, pt
Label1 = "x=" & pt.X & ";y=" & pt.Y '随时显示鼠标的相对于窗体坐标x
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
一念春风十里不如你
推荐于2018-03-11 · TA获得超过1536个赞
知道小有建树答主
回答量:2560
采纳率:68%
帮助的人:295万
展开全部
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim a As RECT
Private Sub Command1_Click()
GetWindowRect Me.hwnd, a
SetCursorPos a.Left + 5, a.Top + 20
End Sub
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
yhu53603fd94fe
2011-01-24 · TA获得超过7838个赞
知道大有可为答主
回答量:7079
采纳率:55%
帮助的人:2838万
展开全部
使用api
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式