From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Use MouseMove event to display x and y axis position in c#

I am trying to display the x and y axis position whenever a user moves the mouse over the graph.  it will update a text box.  I tried to use the mousemove event but i only get the location of the mouse and not the x and y value.  What do i use to get those values.  Thanks
0 Kudos
Message 1 of 3
(13,198 Views)
Hi Layzie292,

You can use the InverseMapDataPoint method as shown below:

private void mouseMove(object sender, MouseEventArgs e)
{
   double xData, yData;
   Point p = new Point(e.X, e.Y);

   waveformGraph1.Plots[0].InverseMapDataPoint(waveformGraph1.PlotAreaBounds, p, out xData, out yData);

   textBox1.Text = xData.ToString();
   textBox2.Text = yData.ToString();
}

If you don't have that method (I can't remember which version first introduced it), refer to this post

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 2 of 3
(13,192 Views)

Thanks

That worked great

0 Kudos
Message 3 of 3
(13,191 Views)