tags:

views:

1538

answers:

2

I am using ZedGraph and I want to zoom to a selected area by holding down Ctrl and dragging the box with the left mouse button instead of clicking and dragging with the middle mouse button.

The default behavior is to zoom with just the left mouse button and to pan with the middle mouse button, but I have switched these two operations already.

Does anyone have any idea how to make panning be called by clicking and dragging with the left button (without holding down Ctrl) and zooming be called by holding down Ctrl and then clicking and dragging with the left button?

A: 

Have you try it by code using:

zg.GraphPane.XAxis.Scale.Min = xxxx;
zg.GraphPane.XAxis.Scale.Max = yyyy;

//and

zgc.ScrollGrace = 0.1;

+2  A: 

The ZedGraphControl allows Pan & Zoom to be controlled through properties of the control. To enable panning with just the left mouse button:

zg1.PanButtons = MouseButtons.Left;
zg1.PanModifierKeys = Keys.None;

and to enable Zoom with Ctrl+Left mouse button:

zg1.ZoomButtons = MouseButtons.Left;
zg1.ZoomModifierKeys = Keys.Control;

The designer properties window doesn't seem to want to let you just specify Control for the Modifier Keys, so you'll have to put it in code - the Form's Load event handler, for example.

Steve Beedie
Thanks, this works perfectly!