Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Get cursor "bring to center" on waveform

I am trying to get an interface as nice as the waveform graph in Labview in my Visual Basic .net program. One thing I have trouble with is the equivalent of the "bring to center" AFTER zooming. Before any zoom or pan, I can get the center easely with the "GetDataPoint" method
Dim xMin, yMin, xMax, yMax As Double
wfmPlot0.GetDataPoint(0, xMin, yMin)
xMax = 1
yMax = 2
wfmPlot0.GetDataPoint(wfmPlot0.HistoryCount - 1, xMax, yMax)
XyCursor1.YPosition = (yMax + yMin) / 2
XyCursor1.XPosition = (xMax + xMin) / 2

But if I zoom into a part of the graph that is not in center, I lost the cursor...
Any Idea?
Lew
0 Kudos
Message 1 of 2
(3,379 Views)
A more general way to accomplish bringing the cursor to the center of the plot area is to use the x and y axis ranges of the associated plot. The implementation is as follows:



Private Sub BringCursorToCenter()
If Not (XyCursor1.Plot Is Nothing) Then
Dim xRange As Range = Range.Empty
Dim yRange As Range = Range.Empty

If Not (XyCursor1.Plot.XAxis Is Nothing) Then
xRange = XyCursor1.Plot.XAxis.Range
End If
If Not (XyCursor1.Plot.YAxis Is Nothing) Then
yRange = XyCursor1.Plot.YAxis.Range
End If

Dim xCenter As Double = (xRange.Maximum + xRange.Minimum) / 2
Dim yCenter As Double = (yRange.Maximum + yRange.Minimum) / 2

XyCursor1.MoveCursor(xCenter, yCenter)
End If
End Sub


The advantage of using the x and y axis ranges for centering is that it is independent of the waveform plot's data and you can call this method from any event handler such as the Click event of a Button, or the Zoom event of a WaveformGraph. To attach an event handler to the Zoom event of the graph, add the following line of code to the constructor of your application:


AddHandler waveformGraph.Zoom, AddressOf OnWaveformGraphZoom


In the OnWaveformGraphZoom method, you can call BringCursorToCenter like this:


Private Sub OnWaveformGraphZoom(ByVal sender As System.Object, ByVal e As NationalInstruments.UI.ActionEventArgs)
BringCursorToCenter()
End Sub
Abhishek Ghuwalewala | Measurement Studio | National Instruments
Message 2 of 2
(3,367 Views)