vb编写程序,要求在两个文本框内分别显示鼠标所在的位置的x坐标和y坐标值!
2013-05-21
展开全部
应该要用到API函数
这是刚在网上找的代码
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI '定义点(Point)结构
X As Long '点在X坐标(横坐标)上的坐标值
Y As Long '点在Y坐标(纵坐标)上的坐标值
End Type
Sub PrintCursorPos()
Dim dl As Long
Dim MyPoint As POINTAPI
dl& = GetCursorPos(MyPoint) '调用函数,获取屏幕鼠标坐标
'Debug.Print "X=" & Str(MyPoint.X) & " and " & "Y=" & Str(MyPoint.Y)
text1.Caption = "当前横坐标:" & Str(MyPoint.X)
text2.Caption = "当前纵坐标:" & Str(MyPoint.Y)
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
对了用上面的代码好像要加一个Time控件,随时更新文本框的内容.
Private Sub Timer1_Timer()
PrintCursorPos
End Sub
这是刚在网上找的代码
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI '定义点(Point)结构
X As Long '点在X坐标(横坐标)上的坐标值
Y As Long '点在Y坐标(纵坐标)上的坐标值
End Type
Sub PrintCursorPos()
Dim dl As Long
Dim MyPoint As POINTAPI
dl& = GetCursorPos(MyPoint) '调用函数,获取屏幕鼠标坐标
'Debug.Print "X=" & Str(MyPoint.X) & " and " & "Y=" & Str(MyPoint.Y)
text1.Caption = "当前横坐标:" & Str(MyPoint.X)
text2.Caption = "当前纵坐标:" & Str(MyPoint.Y)
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
对了用上面的代码好像要加一个Time控件,随时更新文本框的内容.
Private Sub Timer1_Timer()
PrintCursorPos
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询