Custom Microsoft Chart Control Zoom Reset Button

2011-07-18


After you zoom in the Microsoft Chart control. you will see X scroll bar and Y scroll bar which you can scroll the view. Also, you can see two small icons beside the scroll arrow button on scroll bars, the one is on X scroll bar, another one is on Y scroll bar. They are zoom reset buttons.

By default, the zoom reset button only reset one Axis zoom and reset the zoom level to previous scale. When you try to click them, you can see the zoom level reset step by step.

msChartReset00

In some cases, you do not want to the zoom reset works like its default way, but you want the zoom reset just "click one time" and reset the zoom rate to its original level. and also, you might just want one zoom reset button in your UI.

About** how to hidden one of the tow zoom reset buttons** is simple. it is only one line of code:

msChartReset01
chartAreaTrending.AxisY.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;

The SmallScroll Style indicate there is no ResetZoom button displayed.

The custom the zoom reset button event:

private void chartTrending_AxisScrollBarClicked(object sender, ScrollBarEventArgs e)
{
   if (e.ButtonType == ScrollBarButtonType.ZoomReset)
   {
       e.IsHandled = true;
       this.chartAreaTrending.AxisX.ScaleView.ZoomReset(0);
       this.chartAreaTrending.AxisY.ScaleView.ZoomReset(0);

       this.chartAreaTrending.CursorX.SelectionStart = double.NaN;
       this.chartAreaTrending.CursorY.SelectionEnd = double.NaN;
    }
}