Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Coloration between two cursors on a waveform

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

0 Kudos
Message 1 of 5
(2,193 Views)

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.)

~ Paul H
0 Kudos
Message 2 of 5
(2,177 Views)

Thanks a lot for your suggestion, I've not seen this class, I test it asap.

0 Kudos
Message 3 of 5
(2,160 Views)

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);
        }
    }

 

0 Kudos
Message 4 of 5
(2,158 Views)

I found my problem, I nedd to add 

waveformGraph1.Annotations.Add(rangeAnnotation);

 

Thanks again for your help

0 Kudos
Message 5 of 5
(2,155 Views)