0

I want to allow the user to be able to click and drag on the graph to select the points in that area.

I thought a good way to do this would be to use ZoomEvent, because the newState parameter gives the area of the zoom, and I can simply select the points in that area. Is there a way I can access the values in newState and then cancel the zoom? Can I force it to go back to oldState?

private void trendGraphControl_ZoomEvent(ZedGraphControl sender, ZoomState oldState, ZoomState newState)
{
    if (newState.Type == ZoomState.StateType.Zoom) {
        selectPointsInArea(newState);

        // How can I disable this zoom??
    }
}
shadowsora
  • 663
  • 7
  • 15

1 Answers1

1

Actually, the zoom area info that I needed in newState was private. The solution was to save the previous zoom values on mouse down, and then check the new zoom values in the zoom event, before resetting them to the previous values.

double last_x_max, last_x_min, last_y_max, last_y_min;

private bool trendGraphControl_MouseDownEvent(ZedGraphControl sender, MouseEventArgs e)
{
    // Save the zoom values
    last_x_max = sender.GraphPane.XAxis.Scale.Max;
    last_x_min = sender.GraphPane.XAxis.Scale.Min;
    last_y_max = sender.GraphPane.YAxis.Scale.Max;
    last_y_min = sender.GraphPane.YAxis.Scale.Min;
    return false;
}

private void trendGraphControl_ZoomEvent(ZedGraphControl sender, ZoomState oldState, ZoomState newState)
{
    if (newState.Type == ZoomState.StateType.Zoom) {
        double new_x_max = sender.GraphPane.XAxis.Scale.Max;
        double new_x_min = sender.GraphPane.XAxis.Scale.Min;
        double new_y_max = sender.GraphPane.YAxis.Scale.Max;
        double new_y_min = sender.GraphPane.YAxis.Scale.Min;
        selectPointsInArea(new_x_max, new_x_min, new_y_max, new_y_min);
        sender.GraphPane.XAxis.Scale.Max = last_x_max;
        sender.GraphPane.XAxis.Scale.Min = last_x_min;
        sender.GraphPane.YAxis.Scale.Max = last_y_max;
        sender.GraphPane.YAxis.Scale.Min = last_y_min;
    }
}

Thanks for Ramankingdom's comment for sending me in the right direction.

shadowsora
  • 663
  • 7
  • 15