10-02-2011 09:37 PM
Hello, I'm running into a problem with Measurement Studio for C# / .NET, with ScatterGraph annotation tooltip.
If there is a scattergraph cursor defined and whose X or Y position is the same as the current mouse position, the annotation tooltip does not work. Hence, there appears to be some sort of a conflict between the cursor X/Y position and the annotation tooltip.
If I move the cursor X or Y position a bit away from the mouse position, then the annotation tooltip works OK.
Unfortunately I really need the annotation tooltip to work in the case where cursor X or Y position is the same as the mouse position. That's because I'm using the cursor as "follow the mouse position" crosshairs, so the cursor is always aligned with the mouse position in my application.
Appreciate if you can please provide a fix or workaround.
I'm running MeasurementStudio 2010 for C# / .NET on Windows XP.
10-03-2011 11:48 AM
Hi there,
The XYGraph.HitTest(...) method is used to display the tool tips of child elements. In HitTest the cursor takes the priority over the annotations. Hence when you move the mouse over annotation, the annotation tooltip cannot be made visible.
If your intenstion of using the cursor is just to follow the mouse, then there is a better and efficient work around.
Please see the following code. The following code does not require XYCursor.
Point h1, h2;
Point v1, v2;
private void scatterGraph1_MouseMove(object sender, MouseEventArgs e)
{
Rectangle rectangle = scatterGraph1.PlotAreaBounds;
if (rectangle.Contains(e.Location))
{
// calucalte the horizontal and veritical points to draw the lines.
h1 = new Point(rectangle.Left, e.Y);
h2 = new Point(rectangle.Right, e.Y);
v1 = new Point(e.X, rectangle.Top);
v2 = new Point(e.X, rectangle.Bottom);
}
Refresh();
}
// Define a transparent pen, looks cool :)
Pen pen = new Pen(Color.FromArgb(50, 255, 255, 255), 5);
private void scatterGraph1_Paint(object sender, PaintEventArgs e)
{
Rectangle rectangle = scatterGraph1.PlotAreaBounds;
// Draw the calucated points during mouse move.
e.Graphics.DrawLine(pen, h1, h2);
e.Graphics.DrawLine(pen, v1, v2);
}
Hope this helps.
Vijet Patankar
National Instruments
10-03-2011 12:08 PM
Thanks for your reply and the example code.
Unfortunately, it is a little bit more involved in my case, because there are other references to this particular cursor object in my application (e.g. other controls whose behavior is dependent on cursor position).
Is there any way I can override the behavior of XYGraph.HitTest() such that annotations take priority over the cursor?
10-06-2011 05:11 PM
Unfortunately, the order of elements tested in HitTest() are fixed and cannot be modified. Instead, you could create your own cursor class that renders the lines and provides the information that you need about the cursor like X and Y position. Do you need information from the cursor other than just X and Y position? Attached is an example that creates a MyCursor class. The Form1 class then uses the information in this class to output the cursor position to the debug window as a demonstration.