-1
我在C#,WinForm中的圖表上放大鼠標滾輪,當我滾動時,圖表圖像放大到很大,我看不到點上的點y軸,有沒有辦法解決它?
這是代碼,我想我必須更改xmin
和ymax
,但我無法弄清楚方式。鼠標滾輪放大c#當des滾動時不調整圖表大小
這裏是我的代碼:
private void chart_MouseWheel(object sender, MouseEventArgs e)
{
try
{
if (e.Delta < 0)
{
chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset();
chart1.ChartAreas[0].AxisY.ScaleView.ZoomReset();
}
if (e.Delta > 0)
{
double xMin = chart1.ChartAreas[0].AxisX.ScaleView.ViewMinimum;
double xMax = chart1.ChartAreas[0].AxisX.ScaleView.ViewMaximum;
double yMin = chart1.ChartAreas[0].AxisY.ScaleView.ViewMinimum;
double yMax = chart1.ChartAreas[0].AxisY.ScaleView.ViewMaximum;
double posXStart = (chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + xMin)/2;
double posXFinish = (chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + xMax)/2;
double posYStart = (chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + yMin)/2;
double posYFinish = (chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + yMax)/2;
chart1.ChartAreas[0].AxisX.ScaleView.Zoom(posXStart, posXFinish);
chart1.ChartAreas[0].AxisY.ScaleView.Zoom(posYStart, posYFinish);
}
}
catch { }
}