我有以下的WinForms代碼:ZOOM Out功能
void chart1_MouseWheel(object sender, MouseEventArgs e)
{
double xMin = chart1.ChartAreas[0].AxisX.ScaleView.ViewMinimum;
double xMax = chart1.ChartAreas[0].AxisX.ScaleView.ViewMaximum;
if (e.Delta < 0)
{ //chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset();
//chart1.ChartAreas[0].AxisY.ScaleView.ZoomReset();
}
if (e.Delta > 0)
{
double posXStart = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) - (xMax - xMin)/2 ;
double posXFinish = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + (xMax - xMin)/2;
chart1.ChartAreas[0].AxisX.ScaleView.Zoom(posXStart, posXFinish);
}
}
的放大功能正在工作,但是當e.Delta < 0
,我需要縮小功能基於上面的代碼。
舊職,但回到變焦的第一級,花費可能是tremenduous的時間,所以,做盡可能快,就像這樣: 而(chart1.ChartAreas [0] .AxisX.ScaleView .IsZoomed) { chart1.ChartAreas [0] .AxisX.ScaleView.ZoomReset(100); } 並且不要忘記爲您使用的所有軸做 – GnRSlashSP
無需爲此使用循環。根據[ZoomReset文檔](https://msdn.microsoft.com/en-us/library/dd467869.aspx),使用ZoomReset(0)將重置所有縮放操作。 –
感謝@NarcísCalvet - 我已經用你的建議更新了我的答案。 – Ben