Page 1 of 1

Click and Undone_Zoom events collision

Posted: Thu Mar 05, 2009 8:30 am
by 13051164
Env.: VS2008 / Vista / .NET 2.0 / TChart 3.5.3274.30664

Hi,

My chart support zooming + a cursor tool.
When user clicks the chart, I set the cursor tool position at the mouse position.
I initially handled the click in the ClickBaground() event. But it appears that when this event is subscribed, mouse-based Zoom no longer works. Right?

So I switched to using the Click() event. Which lets zoom work but is not good yet: Click() also fires when I do a Zoom or Undo zoom. And since it fires _before_ the Zoomed() or Undone_Zoom() event, I can't filter it out.

How can I solve this issue?

TIA,

Posted: Fri Mar 06, 2009 2:25 pm
by yeray
Hi TIA,
serge wautier wrote:I initially handled the click in the ClickBaground() event. But it appears that when this event is subscribed, mouse-based Zoom no longer works. Right?
Yes you are right. Enabling OnClickBackground event, the zoom is disabled.

Have you tried the combination of OnMouseDown and OnUndoZoom? This could be achieved by doing something like this:

Code: Select all

        Points points1;
        CursorTool cursor1;
        bool moveCursor;

        private void InitializeChart()
        {
            chartController1.Chart = tChart1;
            tChart1.Aspect.View3D = false;

            points1 = new Points(tChart1.Chart);

            points1.FillSampleValues(25);

            cursor1 = new CursorTool(tChart1.Chart);

            moveCursor = true;

            tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
            tChart1.UndoneZoom += new EventHandler(tChart1_UndoneZoom);
        }

        void tChart1_UndoneZoom(object sender, EventArgs e)
        {
            moveCursor = true;
        }

        void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
            if (moveCursor)
            {
                cursor1.XValue = tChart1.Axes.Bottom.CalcPosPoint(e.X);
                cursor1.YValue = tChart1.Axes.Left.CalcPosPoint(e.Y);
                moveCursor = false;
            }
            
        }

Posted: Tue Mar 10, 2009 2:52 pm
by 13051164
Yeray,

I'm not quite sure what the outcome of your logic would achieve.
Especially since MouseDown comes before Zoom, UndoneZoom et al.

Anyway, I found a solution based on the fact that MouseUp() is synchronous with Zoomed() and UndoneZoom() (fired during same WM_LBUTTONUP message) and fires *AFTER* Zoomed() and UndoneZoom(), as opposed to click, which fires *before* those 2.

Cheers,
Serge.

Posted: Tue Mar 10, 2009 3:59 pm
by yeray
Hi Serge,

My code was thought to move the cursor to the start position of the zoom rectangle. Of course, it was an incomplete sample that only pretended to show you the direction of a possible solution and I'd like to apologize if I confused you.

Anyway, I'm happy to see that you found it.