2017-08-11 61 views
-1

我在C#,WinForm中的图表上放大鼠标滚轮,当我滚动时,图表图像放大到很大,我看不到点上的点y轴,有没有办法解决它?
这是代码,我想我必须更改xminymax,但我无法弄清楚方式。鼠标滚轮放大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 { } 
} 

回答

0

我已经删除了我的老回答赞成此一:

变化posXStartposYFinish的定义,posXFinishposYStart,以及:

double posXStart = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) - (xMax - xMin)/2.25; 
double posXFinish = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + (xMax - xMin)/2.25; 
double posYStart = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) - (yMax - yMin)/2.25; 
double posYFinish = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + (yMax - yMin)/2.25; 

如果你想想真正发生了什么,你可以修改通过最后的数字来帮助您获得更好的放大效果。它可以是2或2.5或4或其他。