Click and Undone_Zoom events collision

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
serge wautier
Newbie
Newbie
Posts: 22
Joined: Tue Dec 16, 2008 12:00 am

Click and Undone_Zoom events collision

Post by serge wautier » Thu Mar 05, 2009 8:30 am

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,

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Fri Mar 06, 2009 2:25 pm

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;
            }
            
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

serge wautier
Newbie
Newbie
Posts: 22
Joined: Tue Dec 16, 2008 12:00 am

Post by serge wautier » Tue Mar 10, 2009 2:52 pm

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.

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Tue Mar 10, 2009 3:59 pm

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply