1
我正在尝试在MouseWheel事件期间获取鼠标的位置。在MouseMove事件中,我已成功使用HitTest并以这种方式关闭了我的业务,但由于某些原因,在MouseWheel事件期间,我的HitTest始终为HitTest数据点返回-1值。任何人都可以帮我解决这个问题吗?我将在下面包含我的代码。
我试图完成的是鼠标滚轮的基本放大事件。我想查看光标的位置,然后在任一侧添加当前可查看图表的1/4。在鼠标滚轮事件期间获取光标在图表中的位置
private void chData_MouseWheel(object sender, MouseEventArgs e)
{
try
{
HitTestResult pos = chData.HitTest(e.X, e.Y);
if (e.Delta < 0)
{
chData.ChartAreas[0].AxisX.ScaleView.ZoomReset();
chData.ChartAreas[0].AxisY.ScaleView.ZoomReset();
}
if (e.Delta > 0)
{
double xMin = chData.ChartAreas[0].AxisX.ScaleView.ViewMinimum;
double xMax = chData.ChartAreas[0].AxisX.ScaleView.ViewMaximum;
double yMin = chData.ChartAreas[0].AxisY.ScaleView.ViewMinimum;
double yMax = chData.ChartAreas[0].AxisY.ScaleView.ViewMaximum;
double posXStart = pos.PointIndex - (xMax - xMin)/4;
double posXFinish = pos.PointIndex + (xMax - xMin)/4;
double posYStart = pos.PointIndex - (yMax - yMin)/4;
double posYFinish = pos.PointIndex + (yMax - yMin)/4;
chData.ChartAreas[0].AxisX.ScaleView.Zoom(posXStart, posXFinish);
chData.ChartAreas[0].AxisY.ScaleView.Zoom(posYStart, posYFinish);
}
}
catch { }
}
我的图表被称为chData的方式。我希望这只是一个简单的错字。
在此先感谢!
所以我已经知道PointIndex只有在你实际上是在一个数据点上时才起作用。我需要的是即使我不在数据点上,也知道我在哪个x轴值。任何人有任何想法? – tmwoods