08-03-2018 08:26 AM
Hello everybody,
I'm working on C# with VS2015 with NI Librairies.
I have a waveform and a lot of cursors on it. I would like to colorate the area between two of these cursors.
Do you know how I could do that?
- I thought to use the width of another cursor just between these two cursors to colorate all the area but when I zoom, it doesn't work correctly.
- I would like to avoid to draw a rectangle because it's not really clean.
Thanks for your help
08-03-2018 04:02 PM
I would suggest using a range annotation to fill in the area between the two cursors. Based on your other question, it looks like you are using the Windows Forms controls, so you can use the XYRangeAnnotation
class.
Assuming the pair of cursors are ordered, you could use code like this to update a range annotation with an infinite vertical range:
public Form1( ) { InitializeComponent( ); cursor1.AfterMove += OnCursorMoved; cursor2.AfterMove += OnCursorMoved; MoveRangeAnnotation( ); } private void OnCursorMoved( object sender, AfterMoveXYCursorEventArgs e ) { MoveRangeAnnotation( ); } private void MoveRangeAnnotation( ) { rangeAnnotation.XRange = new Range( cursor1.XPosition, cursor2.XPosition ); }
(If the cursors are not ordered, then the parameters used to create the new Range
would need to be sorted first.)
08-06-2018 01:30 AM
Thanks a lot for your suggestion, I've not seen this class, I test it asap.
08-06-2018 02:17 AM
In fact, I've tested that and nothing happened when I move the cursors. An idea?
public partial class Form1 : Form { XYRangeAnnotation rangeAnnotation; public Form1() { double[] xDatas = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; InitializeComponent(); waveformPlot1.PlotXAppend(xDatas); rangeAnnotation = new XYRangeAnnotation(xAxis1, yAxis1); rangeAnnotation.RangeFillColor = Color.Azure; rangeAnnotation.RangeFillStyle = FillStyle.DiagonalBrick; rangeAnnotation.RangeLineColor = Color.Bisque; xyCursor1.AfterMove += OnCursorMoved; xyCursor2.AfterMove += OnCursorMoved; } private void OnCursorMoved(object sender, AfterMoveXYCursorEventArgs e) { MoveRangeAnnotation(); } private void MoveRangeAnnotation() { rangeAnnotation.XRange = new Range(xyCursor1.XPosition, xyCursor2.XPosition); } }
08-06-2018 02:50 AM
I found my problem, I nedd to add
waveformGraph1.Annotations.Add(rangeAnnotation);
Thanks again for your help