Thanks Andre, I looked at the article and it all makes very good sense. But I must be missing something, because I still can't get meaningful values. I can see the client X/Y mouse positions being different, but after the 2 conversions, I always end up with the same X-value - to 12 decimal places! X1 and X2 always end up as 8.4771212547196626 - not even in my X-axis range.
In my test case my X axis scale runs from 30000000 to 300000000 (30 million to 300 million) and is logarithmic.
Here is my MouseDown and MouseUp code - note that some of the variables (X1, X2, vec1, vec2) are declared at form level.
Private Sub chtGraph_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles chtGraph.MouseDown
Dim hAxis As Axis, vAxis As Axis, dAxis As Axis
Dim pt = New Point(e.X, e.Y)
With chtGraph.Charts(0)
hAxis = .Axis(StandardAxis.PrimaryX)
vAxis = .Axis(StandardAxis.PrimaryY)
dAxis = .Axis(StandardAxis.Depth)
If .MapClientPointToModelPlane(hAxis, vAxis, dAxis, 0, pt, vec1) Then
X1 = hAxis.ConvertModelToScaleCoordinate(vec1.x, True)
Else
X1 = Double.NaN ' indicate that we couldn't determine position
End If
End With
End Sub
Private Sub chtGraph_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles chtGraph.MouseUp
Dim dDiff As Double
Dim hAxis As Axis, vAxis As Axis, dAxis As Axis
Cursor = Cursors.Default
Dim pt = New Point(e.X, e.Y)
With chtGraph.Charts(0)
hAxis = .Axis(StandardAxis.PrimaryX)
vAxis = .Axis(StandardAxis.PrimaryY)
dAxis = .Axis(StandardAxis.Depth)
If Not Double.IsNaN(X1) Then ' mousedown position was valid
If .MapClientPointToModelPlane(hAxis, vAxis, dAxis, 0, pt, vec2) Then
X2 = hAxis.ConvertModelToScaleCoordinate(vec2.x, True)
dDiff = Math.Abs(X2 - X1)
If dDiff <> 0 Then MsgBox("Frequency difference is " & dDiff.ToString("#0.000000") & "MHz", MsgBoxStyle.Information, "QDL Viewer")
End If
End If
End With
End Sub
This isn't identical to the code in the article, but its effect should be the same as far as I can see. But clearly something is not right - probably something quite obvious! I don't mind feeling stupid if I can get the result I want. Thanks.