Controlling zoom/pan with the control key

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Bravo1
Newbie
Newbie
Posts: 2
Joined: Fri Sep 02, 2011 12:00 am

Controlling zoom/pan with the control key

Post by Bravo1 » Thu May 31, 2012 7:04 am

Hey

I need to redefine when to pan and zoom in a chart on a WinForm. Actually what I want is to use the zoom tool like normal (left click), but when the user press Ctrl while left clicking I want to pan the chart instead - and use the right click as a normal popup menu. I have solved the problem with disabling pan-funtionality on right click but how do I solve the "Ctrl+Left key" problem?

/Claus

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Controlling zoom/pan with the control key

Post by Sandra » Fri Jun 01, 2012 8:35 am

Hello Claus,
I suggest you use MouseDown and ModifierKeys method to achieve as you want Ctrl MouseLeft as do in next lines of code:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            Steema.TeeChart.Styles.Bar bar1 = new Bar(tChart1.Chart);
            bar1.FillSampleValues();
            bar1.SideMargins = false;
            tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
        }

        void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
            if (ModifierKeys == Keys.Control && e.Button == MouseButtons.Left)
            {
                tChart1.Zoom.Allow = false;
                tChart1.Panning.MouseButton = MouseButtons.Left;
               
            }
            else
            {
                tChart1.Zoom.Allow = true;
                tChart1.Panning.MouseButton = MouseButtons.Right;
            }
        }
Can you tell us if previous code works as you want? If you have any problems please, let me know.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Bravo1
Newbie
Newbie
Posts: 2
Joined: Fri Sep 02, 2011 12:00 am

Re: Controlling zoom/pan with the control key

Post by Bravo1 » Mon Jun 04, 2012 7:37 am

Hey

It did not work with MouseDown - but it works perfectly in a KeyUp/KeyDown combination - I was just missing the "tChart1.Panning.MouseButton" property, so now I have a working solution - thanks!

/Claus

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Controlling zoom/pan with the control key

Post by Sandra » Mon Jun 04, 2012 9:55 am

Hello Claus,

I am glad that your can solve your problem.

Thanks for your information,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply