How to Change the handler of Zooming

2 posts, 0 answers
  1. Hassan
    Hassan avatar
    2 posts
    Member since:
    Feb 2015

    Posted 25 Mar 2015 Link to this post

    Dear Telerik, 


    how to change the handler of the zooming instead of CTRL & mouse scroll.
  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 30 Mar 2015 Link to this post

    Hello Hassan,

    Thank you for writing.

    To change the modifier key of the pan and zoom controller you should create a class that inherits the default controller and override the OnMouseWheel method. For example you can use the following code to zoom with the shift key:
    class MyPanZoomControler : ChartPanZoomController
    {
        protected override ActionResult OnMouseWheel(MouseEventArgs e)
        {
            if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift && this.Area is CartesianArea)
            {
                IChartView chartView = this.Area.View;
     
                double zoomWidth = chartView.ZoomWidth;
     
                if (this.PanZoomMode == ChartPanZoomMode.Horizontal || this.PanZoomMode == ChartPanZoomMode.Both)
                {
                    zoomWidth += ((double)e.Delta / 1200d);
                }
     
                double zoomHeight = chartView.ZoomHeight;
     
                if (this.PanZoomMode == ChartPanZoomMode.Vertical || this.PanZoomMode == ChartPanZoomMode.Both)
                {
                    zoomHeight += ((double)e.Delta / 1200d);
                }
     
                double virtualHorizontalPosition = e.X - this.Area.AreaModel.LayoutSlot.X - chartView.PlotOriginX;
                double plotAreaVirtualWidth = this.Area.AreaModel.LayoutSlot.Width * chartView.ZoomWidth;
                double relativeHorizontalPosition = virtualHorizontalPosition / plotAreaVirtualWidth;
                double newPlotAreaVirtualWidth = this.Area.AreaModel.LayoutSlot.Width * zoomWidth;
                double newPanOffsetX = (newPlotAreaVirtualWidth * relativeHorizontalPosition) - (e.X - this.Area.AreaModel.LayoutSlot.X);
                newPanOffsetX = this.ClampValue(newPanOffsetX, 0, this.Area.AreaModel.LayoutSlot.Width * (zoomWidth - 1d));
     
                double virtualVerticalPosition = e.Y - this.Area.AreaModel.LayoutSlot.Y - chartView.PlotOriginY;
                double plotAreaVirtualHeight = this.Area.AreaModel.LayoutSlot.Height * chartView.ZoomHeight;
                double relativeVerticalPosition = virtualVerticalPosition / plotAreaVirtualHeight;
                double newPlotAreaVirtualHeight = this.Area.AreaModel.LayoutSlot.Height * zoomHeight;
                double newPanOffsetY = (newPlotAreaVirtualHeight * relativeVerticalPosition) - (e.Y - this.Area.AreaModel.LayoutSlot.Y);
                newPanOffsetY = this.ClampValue(newPanOffsetY, 0, this.Area.AreaModel.LayoutSlot.Height * (zoomHeight - 1d));
     
                zoomWidth = this.ClampValue(zoomWidth, 1d, 100d);
                zoomHeight = this.ClampValue(zoomHeight, 1d, 100d);
     
                this.Area.View.Zoom(zoomWidth, zoomHeight);
                this.Area.View.Pan(-newPanOffsetX, -newPanOffsetY);
            }
     
            return base.OnMouseWheel(e);
        }
     
        private double ClampValue(double value, double minValue, double maxValue)
        {
            return Math.Max(minValue, Math.Min(value, maxValue));
        }
    }

    Please let me know if there is something else I can help you with. 
     
    Regards,
    Dimitar
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top