-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 { }
}