如何使用C#使光标线在图表中跟随鼠标

在此处输入图像描述

下图显示了我项目中的图表。 如您所见,有两条虚线交叉线。 我被要求让它跟随鼠标,但现在只有当我点击它移动的图表时。 我试图使用CursorPositionChanging但它没有用。 CursorEventHandler也未显示在下面的命令中:

this.chart1.CursorPositionChanging += new System.Windows.Forms.DataVisualization.Charting.Chart.CursorEventHandler(this.chart1_CursorPositionChanging); 

我们需要为此添加额外的lib吗? 所以我现在有两个问题:1。使线条跟随鼠标2.缺少CursorEventHandler

该项目是使用C#的窗体表单应用程序

该图表支持“MouseMove”事件,每次鼠标在图表中移动时都会触发该事件。 MouseEventArgs包含鼠标的位置,因此每次事件触发时,您都可以根据该数据移动虚线。

 private void chData_MouseMove(object sender, MouseEventArgs e) { Point mousePoint = new Point(eX, eY); Chart.ChartAreas[0].CursorX.SetCursorPixelPosition(mousePoint, true); Chart.ChartAreas[0].CursorY.SetCursorPixelPosition(mousePoint, true); // ... }