Reputation: 11
I am developing a VB .NET program in the VisualStudio 2022 environment and I use the ScottPlot package for generating two-dimensional graphs. In ScottPlot 4 version, it was possible to obtain the coordinates of the mouse position over the graph using the .MouseMove event and the .GetMouseCoordinates() function. Is there a similar option in the ScottPlot 5 package?
I wish to display to the user the coordinates pointed by the mouse.
Upvotes: 0
Views: 887
Reputation: 1173
It seems that the function is not available anymore, therefore I think we can achieve the same thing using the GetCoordinates
function. You can use it within the MouseMove event:
Private Sub CustomMouseMove(sender As Object, e As MouseEventArgs)
Dim newCoords As ScottPlot.Coordinates = FormPlot1.Plot.GetCoordinates(New ScottPlot.Pixel(e.X, e.Y))
Label1.Text = newCoords.X.ToString("0.00") + ", " + newCoords.Y.ToString("0.00")
End Sub
Alternatively, by creating a function that calculates the mouse position on the control and convert them to coordinates on the plot:
Public Function GetMouseCoordinates(ByVal plot As ScottPlot.WinForms.FormsPlot) As ScottPlot.Coordinates
With FormPlot1.PointToClient(MousePosition)
Return FormPlot1.Plot.GetCoordinates(New ScottPlot.Pixel(.X, .Y))
End With
End Function
Upvotes: 0