Overview
With the Measurement Studio complex graph .NET control, you can easily leverage custom drawing services and helper methods to extend the functionality of the cursor. The ComplexPlot base class provides several members to help you create custom cursors, including the following events:
- AfterDraw event—Occurs immediately after the cursor is drawn. You typically handle this event if you want to augment the default visual representation of the cursor with additional custom drawing. For more information, refer to Augmenting the Default Drawing of the Cursor.
- BeforeDraw event—Occurs immediately before the cursor is drawn. You typically handle this event if you want to completely handle the way that the cursor is drawn. If you completely handle the implementation for drawing the cursor, you can set the Cancel property of the event arguments to true to indicate that you have completely handled the implementation and that the cursor should not perform any additional drawing. For more information, refer to Completely Implementing the Cursor Drawing.
Note: It is not always necessary to use the BeforeDraw and AfterDraw events to extend the functionality of the cursor. You can customize the PointStyle of the cursor and the crosshair LineStyle without using these events. For more information, refer to Creating a Custom Line Style for the Measurement Studio Windows Forms Graph .NET Control in the NI Measurement Studio Help.
Augmenting the Default Drawing of the Cursor
The attached example creates a DisplayPositionCursor class, which derives from ComplexCursor. This class overrides the protected virtual OnAfterDraw method, which the AfterDraw event is raised through, instead of registering for the event. Overriding this method has the advantage of encapsulating the implementation. This example uses the AfterDraw event to demonstrate how to do additional drawing on a cursor that is already drawn.
The next example creates an instance of the DisplayPositionCursor class, assigns it a plot, and adds it to the graph Cursors collection:
VB.NET
Dim sineData As Double() = BasicFunctionGenerator.GenerateSineWave(1.0, 1.0, 0.0, 0.0, 100.0, 100)
Dim data(sineData.Length - 1) As ComplexDouble
Dim i As Integer
For i = 0 To sineData.Length - 1
data(i) = New ComplexDouble(i, sineData(i))
Next i
ComplexGraph1.PlotComplex(data)
Dim plot As ComplexPlot = ComplexGraph1.Plots(0)
Dim positionCursor As DisplayPositionCursor = New DisplayPositionCursor(plot)
ComplexGraph1.Cursors.Add(positionCursor)
C#
double[] sineData = BasicFunctionGenerator.GenerateSineWave(1.0, 1.0, 0.0, 0.0, 100.0, 100);
ComplexDouble[] data = new ComplexDouble[sineData.Length];
for(int i = 0; i < data.Length; i++)
data[i] = new ComplexDouble(i, sineData[i]);
complexGraph1.PlotComplex(data);
ComplexPlot plot = complexGraph1.Plots[0];
DisplayPositionCursor positionCursor = new DisplayPositionCursor(plot);
complexGraph1.Cursors.Add(positionCursor);
The following image shows the plotted data on complexPlot1:

As you move the cursor on the plot, the cursor position updates because AfterDraw is called each time the cursor draws.
Completely Implementing the Cursor Drawing
The attached example creates a DoubleLineCursor class, which derives from ComplexCursor. This class overrides the protected virtual OnBeforeDraw method, which the BeforeDraw event is raised through, instead of registering for the event. Overriding this method has the advantage of encapsulating the implementation. This example uses BeforeDraw to demonstrate how to take full control of drawing the cursor by canceling the event.
The next example creates an instance of the DoubleLineCursor class, assigns it a plot, and adds it to the graph Cursors collection.
VB.NET
Dim sineData As Double() = BasicFunctionGenerator.GenerateSineWave(1.0, 1.0, 0.0, 0.0, 100.0, 100)
Dim data(sineData.Length - 1) As ComplexDouble
Dim i As Integer
For i = 0 To sineData.Length - 1
data(i) = New ComplexDouble(i, sineData(i))
Next i
ComplexGraph1.PlotComplex(data)
Dim plot As ComplexPlot = ComplexGraph1.Plots(0)
Dim doubleLineCursor As DoubleLineCursor = New DoubleLineCursor(plot)
ComplexGraph1.Cursors.Add(doubleLineCursor)
C#
double[] sineData = BasicFunctionGenerator.GenerateSineWave(1.0, 1.0, 0.0, 0.0, 100.0, 100);
ComplexDouble[] data = new ComplexDouble[sineData.Length];
for(int i = 0; i < data.Length; i++)
data[i] = new ComplexDouble(i, sineData[i]);
complexGraph1.PlotComplex(data);
ComplexPlot plot = complexGraph1.Plots[0];
DoubleLineCursor doubleLineCursor = new DoubleLineCursor(plot);
complexGraph1.Cursors.Add(doubleLineCursor);
The following image shows DoubleLineCursor:

Downloads
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
