vb 获取鼠标在窗口内的屏幕坐标

vb 获取鼠标在窗口内的屏幕坐标,第1张

看到你的问题补充就不知道你想要写成什么样子的了。

给你两段代码把。

一、获取鼠标屏幕上的坐标

'坐标显示在Text1,Text2

'建一个Timer1,Text1,Text2

'代码如下。

'============

Private Type POINTAPI

x As Long

y As Long

End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Dim p As POINTAPI

Private Sub Form_Load()

Timer1Interval = 10

End Sub

Private Sub Timer1_Timer()

GetCursorPos p

Text1Text = px

Text2Text = py

End Sub

二、获取鼠标在窗体内的坐标

'坐标显示在标题上

'运行此程序需要再窗体添加控件Timer

Option Explicit

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Private Type POINTAPI

x As Long

y As Long

End Type

Private Sub Form_Load()

Timer1Interval = 10 '设置获取鼠标坐标间隔

End Sub

Private Sub Timer1_Timer()

Dim P As POINTAPI

GetCursorPos P '获取鼠标在屏幕中的位置

ScreenToClient Mehwnd, P '转换为本窗体的坐标

Dim t As Boolean

t = Px >= 0 And Py >= 0 And Px < MeWidth / ScreenTwipsPerPixelX And Py <= MeHeight / ScreenTwipsPerPixelY

If t Then MeCaption = "x=" & Px & "y=" & Py '按像素显示坐标

'If t Then MeCaption = "x=" & Px ScreenTwipsPerPixelX & "y=" & Py ScreenTwipsPerPixelY '按缇显示坐标

End Sub

Point

p

=

CursorPosition;

pX;

//当前X坐标

pY;

//当前Y坐标

以上代码在任意地方执行,就可取得鼠标在屏幕上的X

Y坐标。

以上就是关于vb 获取鼠标在窗口内的屏幕坐标全部的内容,包括:vb 获取鼠标在窗口内的屏幕坐标、如何获得当前鼠标的屏幕坐标(c#)、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9613276.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存