0

Intro

I use ZedGraph to display curves on a graph. I created cross-hairs which display the value of the point it aims in the legend. I can move the cross-hair with the mouse or the keyboard from a point to another.

Issue

When I move the cross-hair with the mouse, the display of the point value is the correct one. When I try to move it with the keyboard, it display the value of the previous spotted point. When I use the debugger to see what happens, it show the correct value.

Example

lets consider a 5 points curve A(0,0); B(1,1); C(2,2); D(3,3); E(4,4). If I move the cross-hair with the mouse from A to B the display was y = 0 x = 0 and is y = 1 x = 1 after the mouse move. If I use the keyboard to go from B to C the display stay at y = 1 x = 1 (whereas the debugger says y = 2 x = 2) and if I move from C to D the display is y = 2 x = 2 whereas the debugger says y = 3 x = 3. If I move from D to E with the mouse, it displays the correct value.

How can I fix that ?

Edit

The drawing and legend is the same function, driven with just a few difference, depending of who called the function.

Here's the keyboard event :

private void lineGraphControl1_KeyDown(Object sender, KeyEventArgs e)
{
    bool first = false;
    bool second = false;
    if (e.Modifiers == Keys.Control && !showTwoCursor)
    {
        first = true;
    }
    else if (showTwoCursor)
    {
        if (crosshairList[0].Index < crosshairList[1].Index)
        {
            first = e.Modifiers == Keys.Control;
            second = e.Modifiers == Keys.Alt;
        }

    }
    if(first || second)
    {
        Crosshair crosshair = null;
        if (first)
           crosshair = crosshairList[0];
        if (second)
           crosshair = crosshairList[1];


        if (e.KeyCode == Keys.Left && crosshair.Index > 0)
            crosshair.Index--;
        else if (e.KeyCode == Keys.Right && crosshair.Index + 1 < curve.NPts)
            crosshair.Index++;
        else
            return;

        drawCursors(first, second, true);
    }
}

and the mouse event :

private bool lineGraphControl1_MouseMoveEvent(ZedGraphControl sender, MouseEventArgs e)
{
        
    // Draw the cursor near the mouse location.
    drawCursors(drawFirstCursor, drawSecondCursor, false, e.Location);
    return false;
}

I don't see anything about refreshing screen event...

Community
  • 1
  • 1
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
  • It looks like you don't refresh the information on the screen at the right time. Perhaps your application first refresh the position information on the screen and then move the cursor. Try to debug step by step to see the execution order. And check if it's right. – Maxime Mangel Oct 23 '14 at 12:07

1 Answers1

1

Using Zedgraph some of the Handlers can call the mouse and the keyboard event.

So when you use keyboard, the mouse event can be call too, depending of your Handler.

That can produce your bug.

Maxime Mangel
  • 1,906
  • 16
  • 18