我正在开发一个带有Windows窗体图表的WindowsFormsHost的WPF应用程序。我已经实现了以下代码,允许通过鼠标滚轮进行缩放。
int deltaScrollTotal;
private void chart_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
{
//System.Windows.Forms.MessageBox.Show("ECEMT");
int maxChangeRange = 21;
int minChangeRange = -1;
int deltaScroll = e.Delta / Math.Abs(e.Delta);
deltaScrollTotal += deltaScrollTotal + deltaScroll > minChangeRange
&& deltaScrollTotal + deltaScroll < maxChangeRange
? deltaScroll : 0;
// Additional calculation in order to obtain pseudo
// "positional zoom" feature
double minXScale = (double)e.X / (double)MyWinformChart.Width;
double maxXScale = 1 - minXScale;
double minYScale = (double)e.Y / (double)MyWinformChart.Height;
double maxYScale = 1 - minYScale;
// Max and min values into which axis need to be scaled/zoomed
double maxX = MyWinformChart.ChartAreas[0].AxisX.Maximum
- deltaScrollTotal * maxXScale;
double minX = MyWinformChart.ChartAreas[0].AxisX.Minimum
+ deltaScrollTotal * minXScale;
double maxY = MyWinformChart.ChartAreas[0].AxisY.Maximum
- deltaScrollTotal * minYScale;
double minY = MyWinformChart.ChartAreas[0].AxisY.Minimum
+ deltaScrollTotal * maxYScale;
MyWinformChart.ChartAreas[0].AxisX.ScaleView.Zoom(minX, maxX);
MyWinformChart.ChartAreas[0].AxisY.ScaleView.Zoom(minY, maxY);
}
事件处理程序设置如下:
MyWinformChart.MouseWheel += new System.Windows.Forms.MouseEventHandler(chart_MouseWheel);
我的问题是当我点击WPF应用程序中的任何其他按钮时,我无法通过滚动来缩放。我不太确定这可能是什么。
在Windows 7计算机上使用VS2012 Express