Reputation: 658
I have a chart (the standard chart that comes with win-forms visual studio) that I've set up zooming on. Every time this chart is zoomed I would like to run a function, however I cannot find an event that is triggered on zoom. I looked though the list of events and the only one that I thought may work was "AxisViewChanged", however this is triggered on many changes and I don't know how to single out just the zoom changes. Is there some zoom event I'm missing? or does this just not exist?
Upvotes: 3
Views: 5872
Reputation: 24403
You can do something like this
double oldSelStart = -1;
double oldSelEnd = -1;
private void chart1_AxisViewChanged(object sender, ViewEventArgs e)
{
double newSelStart = chart1.ChartAreas["Default"].CursorX.SelectionStart;
double newSelEnd = chart1.ChartAreas["Default"].CursorX.SelectionEnd;
const double TOLERANCE = 0.1;
if (Math.Abs(oldSelEnd - newSelEnd) > TOLERANCE || Math.Abs(newSelStart - oldSelStart) > TOLERANCE)
{
oldSelStart = newSelStart;
oldSelEnd = newSelEnd;
//Zoom has actually changed do your stuff
}
}
Basically you remember your old zoom ranges and handle AxisViewChanged yourself and determine if the zoom has actually changed
Upvotes: 4