直接用Point取颜色~Private Const LineColor = vbRedPrivate Sub Form_Load() With Picture1 .AutoRedraw = True .ScaleMode = vbPixels .ForeColor = LineColor Picture1.Line (0, 0)-(.ScaleWidth, .ScaleHeight) End With End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim i As Integer
With Picture1 For i = 0 To .ScaleHeight If .Point(X, i) = LineColor Then Me.Caption = i Exit Sub End If Next End With End Sub
画上去的线并非对象,无法用鼠标捕捉.
如果你要得到的是:鼠标指针处对应的百分比,那可以使用MOUSEMOVE事件来获得鼠标的X,Y坐标,再结合你画的曲线所代表的比例,就可以计算出来了.
With Picture1
.AutoRedraw = True
.ScaleMode = vbPixels
.ForeColor = LineColor
Picture1.Line (0, 0)-(.ScaleWidth, .ScaleHeight)
End With
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer
With Picture1
For i = 0 To .ScaleHeight
If .Point(X, i) = LineColor Then
Me.Caption = i
Exit Sub
End If
Next
End With
End Sub