Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
540
Zooming an Panning a Gantt-chart using the mouse
posted

 Hi,

sorry to be almost "spamming" but we need some answers pretty soon ... Is there a way to zoom using the mouse and when in zoom (so not scale 1) implement the right-click in a manner that panning becomes possible ?

If so, could you give some tips (or working code :-) ) to get this done ?

 

Thanks,

 

Wim

Parents
  • 17605
    posted

    You can try using:

    public class PanningTool : InteractionTool

    {

    private Point prevPoint;

    private AxisAppearance axisApp;

    private Axis axis;

    /// <summary>

    /// Initializes a new instance of the <see cref="PanningTool"/> class.

    /// </summary>

    /// <param name="ultraChart">The ultra chart.</param>

    public PanningTool(UltraChart ultraChart): base(ultraChart)

    {

    }

     

    /// <summary>

    /// Determines whether this tool can start.

    /// </summary>

    /// <returns>

    /// <c>true</c> if this tool can start; otherwise, <c>false</c>.

    /// </returns>

    public override bool CanStart()

    {

    if (this.LastInput.MouseEventArgs.Button == MouseButtons.Right)

    {

    return true;

    }

    return false;

    }

    /// <summary>

    /// Called when this tool starts.

    /// </summary>

    public override void Start()

    {

    GridLayer gridLayer = this.ChartCore.GetGridLayer() as GridLayer;

    this.axis = gridLayer.Grid["X"] as Axis;

    this.axisApp = (AxisAppearance)this.axis.GetAppearance();

    this.prevPoint = this.LastInput.ViewPoint;

    System.Windows.Forms.Cursor.Current = Cursors.Hand;

    }

    /// <summary>

    /// Called when this tool is started and the mouse is moved.

    /// </summary>

    public override void MouseMove()

    {

    base.MouseMove();

    int dx = this.LastInput.ViewPoint.X - prevPoint.X;

    double correction = -64;

    double coef = (axis.MapRange + correction) * (1 - axis.Scale);

    double scrollOffset = dx / coef;

    if (double.IsNaN(scrollOffset))

    return;

    double d = axisApp.ScrollScale.Scroll + scrollOffset;

    if (d < 0)

    {

    d = 0;

    }

    if (d > 1)

    {

    d = 1;

    }

    axisApp.ScrollScale.Scroll = d;

    this.prevPoint = this.LastInput.ViewPoint;this.InvalidateView(CacheLevel.ImageLevelCache);

    }

    /// <summary>

    /// Called when this tool stops.

    /// </summary>

    public override void Stop()

    {

    System.Windows.Forms.
    Cursor.Current = Cursors.Default;base.Stop();

    }

    }

     ...

    PanningTool panningTool = new PanningTool(this.ultraChart1);

    this.ultraChart1.AddMouseDownTool(panningTool);

     

    You can also try looking at the WinForms ChartSamples - Chart Interaction.

     

Reply Children