Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

About cursors, labels and CursorSnapMode.ToPlot

I have been in trouble while using cursors.

First I m looking for a way not to print the ";" in the label. I cannot override DrawLabel, and I dont think I can add an AfterDraw event because the label position is not fixed. It would be nice to have a label format instead of both a XFormat and a YFormat ( like : myCursor.LabelFormat = "{0:0.000} - {1:0.000}" ). By the way my goal is to show only the Y value.

Also my graph is freezing when I m move my cursors. I tried to use a thread but it doesnt change anything : even when I dont add an event handler for AfterMove the graph is freezing. It looks like moving a cursor (CursorSnapMode.ToPlot) is quite time-consuming.
Is there a way to avoid : mouse moving event handler -> compute x position -> use a thread to move the cursors to the position ?


Thank you for your time,
Pipo
0 Kudos
Message 1 of 4
(3,653 Views)
With regards to your first question, here is a custom cursor class that draws a label next to the cursor. It can be any string you want it to be.


using NationalInstruments.UI;
using System.Drawing;
using System;

public class CustomCursor : XYCursor
{
private const string DefaultLabel = "blah, blah";
private string _label;

public CustomCursor()
{
_label = DefaultLabel;
}

public string Label
{
get
{
return _label;
}
set
{
if (value == null)
throw new ArgumentNullException("value");

if (_label != value)
{
_label = value;
//causes cursor to redraw.
Invalidate();
}
}
}

protected override void OnAfterDraw(AfterDrawXYCursorEventArgs e)
{
base.OnAfterDraw(e);

SizeF labelSize = e.Graphics.MeasureString(_label, LabelFont);
PointF referencePoint = new PointF(e.PointBounds.X + (e.PointBounds.Width / 2), e.PointBounds.Y + (e.PointBounds.Height / 2));
AlignmentArgs aligmentArgs = new AlignmentArgs(e.Bounds, referencePoint, labelSize, (float)PointSize.Width / 2, (float)PointSize.Height / 2);
PointF labelPoint = LabelAlignment.AdjustPosition(this, aligmentArgs);

using (Brush backgroundBrush = new SolidBrush(LabelBackColor))
using (Brush foregroundBrush = new SolidBrush(LabelForeColor))
{
e.Graphics.FillRectangle(backgroundBrush, new RectangleF(labelPoint, labelSize));
e.Graphics.DrawString(_label, LabelFont, foregroundBrush, labelPoint);
}
}

}


To use it, add an instance of it to the Cursors collection on the graph.

How many points are you using in your graph? The cursor has to go through the points to determine which point is closest on the plot.
0 Kudos
Message 2 of 4
(3,644 Views)
Thank you for your learning code breeve.

I am using a lot of points on my graph (10k/plot), and a few plots. Moreover I would like to use a vertical cursor to move all the cursors of my graph at the same time.
I coded this, but however I am currently only trying to move one vertical cursor on a plot without freezing my application.
Of course I m not blaming MS at all, I know my application already is performing quite a lot background activities, I m looking for a way to my move cursors without freezing.


Pipo
0 Kudos
Message 3 of 4
(3,623 Views)
I created a scratch project with two plots (see screenshot). Each plot contains 10,000 points. I added one cursor and moved it interactively and it responded really well. From some of your previous posts, I am assuming you are using 7.1.

Try creating a simple application that moves a single cursor around with your data. See if the cursor has troubles responding.

My test project was using CursorSnapMode.ToPlot. CursorSnapMode.NeareastPoint will be slower because the cursor takes into consideration all the points on multiple plots. Of course, CursorSnapMode.Floating will be the fastest because no points are taken into consideration.

What snap mode are you using?
Message 4 of 4
(3,612 Views)