用VB怎样实现像图片这样随着鼠标移动即时显示曲线坐标,我用的是picture控件画的曲线(如图)
希望编程高手帮忙解决啊,在做“科研训练”急用,最好能有代码,发到邮箱719781109@qq.com,好的建议也可以,3q...
希望编程高手帮忙解决啊,在做“科研训练”急用,最好能有代码,发到邮箱719781109@qq.com,好的建议也可以,3q
展开
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
测试通过
步骤:获取鼠标屏幕位置,转换成窗口位置,作相对换算。
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
Dim pt As POINTAPI
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
GetCursorPos pt '获取鼠标屏幕位置
ScreenToClient Me.hwnd, pt '转换成窗口位置
If pt.x > Picture1.left / Screen.TwipsPerPixelX And _
pt.x < (Picture1.left + Picture1.Width) / Screen.TwipsPerPixelX _
And pt.y > Picture1.top / Screen.TwipsPerPixelY And _
pt.y < (Picture1.top + Picture1.Height) / Screen.TwipsPerPixelY Then
Picture1.Cls
Picture1.Print pt.x - Picture1.left / Screen.TwipsPerPixelX & "," & _
(Picture1.top + Picture1.Height) / Screen.TwipsPerPixelY - pt.y
End If
End Sub
步骤:获取鼠标屏幕位置,转换成窗口位置,作相对换算。
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
Dim pt As POINTAPI
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
GetCursorPos pt '获取鼠标屏幕位置
ScreenToClient Me.hwnd, pt '转换成窗口位置
If pt.x > Picture1.left / Screen.TwipsPerPixelX And _
pt.x < (Picture1.left + Picture1.Width) / Screen.TwipsPerPixelX _
And pt.y > Picture1.top / Screen.TwipsPerPixelY And _
pt.y < (Picture1.top + Picture1.Height) / Screen.TwipsPerPixelY Then
Picture1.Cls
Picture1.Print pt.x - Picture1.left / Screen.TwipsPerPixelX & "," & _
(Picture1.top + Picture1.Height) / Screen.TwipsPerPixelY - pt.y
End If
End Sub
追问
追答
上边是给你演示坐标显示,从屏幕坐标,到窗口坐标,再到图像框坐标三步转换,你看懂思路自己改编,肯定不能照搬。上有cls语句自然是把图像清了,改用label显示,背景设为透明即可。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询