A lot of people already asked this but I haven't found an answer that works for me. I just want to make the user unable to zoom out/pan outside a certain range (between 0 and "size" in my example below). I managed to limit the zooming by using the ZoomEvent and setting the Max and Min values manually, but I can't figure out how to do the same for panning. Here is a bit of code:
int size = 40000;
graphControl.ZoomEvent += GraphControl_ZoomEvent;
graphControl.Scroll += GraphControl_Scroll;
graphControl.ScrollEvent += GraphControl_Scroll;
private void GraphControl_Scroll(object sender, ScrollEventArgs e)
{
if (graphControl.MasterPane.PaneList[0].XAxis.Scale.Max > size)
graphControl.MasterPane.PaneList[0].XAxis.Scale.Max = size;
if (graphControl.MasterPane.PaneList[0].XAxis.Scale.Min < 0)
graphControl.MasterPane.PaneList[0].XAxis.Scale.Min = 0;
graphControl.MasterPane.AxisChange();
graphControl.Refresh();
}
private void GraphControl_ZoomEvent(ZedGraphControl sender, ZoomState oldState, ZoomState newState)
{
if (sender.MasterPane.PaneList[0].XAxis.Scale.Max > size)
sender.MasterPane.PaneList[0].XAxis.Scale.Max = size;
if (sender.MasterPane.PaneList[0].XAxis.Scale.Min < 0)
sender.MasterPane.PaneList[0].XAxis.Scale.Min = 0;
sender.MasterPane.AxisChange();
sender.Refresh();
}
The code above almost does it, but the Min and Max values update only after I've let go of my panning button, I want to limit it at all times (including during the panning). I also think it's worth mentioning that the Scroll event isn't firing at all.
Thank you in advance!
Subscribe to MouseMoveEvent and use the same code like in ZoomEvent.
Additionally, do this only if pan mouse button (middle) is pressed (or Ctrl and left mouse button). If you limit Min side, you have to set the Max side also to maintain the same axis span if you don't want to change the scale of the XAxis.
In this example below I limited only one side. Return false to allow the execution of other actions (panning).