C# 图表中的光标线

C# 图表中的光标线,c#,charts,C#,Charts,我在一个C#windows窗体项目中使用一个图表控件。我想让虚线跟随鼠标在图表上移动。我可以使线以光标或数据点为中心;在这一点上,我是灵活的。我在下面附上了一张我正在寻找的东西的屏幕截图 因此,在这里您可以看到黑色虚线(光标不会出现,因为它是一个屏幕抓取)。我已经有了一个mouseMove事件,但我不确定要在该mouseMove中包含哪些代码才能使其工作(现在它只在我单击鼠标时工作,但我认为这只是因为我启用了CursorX.IsUserSelection)。我已经在图表创建函数中设置了行的格式

我在一个C#windows窗体项目中使用一个图表控件。我想让虚线跟随鼠标在图表上移动。我可以使线以光标或数据点为中心;在这一点上,我是灵活的。我在下面附上了一张我正在寻找的东西的屏幕截图

因此,在这里您可以看到黑色虚线(光标不会出现,因为它是一个屏幕抓取)。我已经有了一个mouseMove事件,但我不确定要在该mouseMove中包含哪些代码才能使其工作(现在它只在我单击鼠标时工作,但我认为这只是因为我启用了CursorX.IsUserSelection)。我已经在图表创建函数中设置了行的格式,但是是否有一些CursorX.LineEnable函数或类似的功能?我找不到。我知道我可以用一个画过的物体来完成这项工作,但我希望避免麻烦
提前谢谢!我将在下面列出我的行格式。这在图表创建部分

        chData.ChartAreas[0].CursorX.IsUserEnabled = true;
        chData.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
        chData.ChartAreas[0].CursorY.IsUserEnabled = true;
        chData.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;

        chData.ChartAreas[0].CursorX.Interval = 0;
        chData.ChartAreas[0].CursorY.Interval = 0;
        chData.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
        chData.ChartAreas[0].AxisY.ScaleView.Zoomable = true;

        chData.ChartAreas[0].CursorX.LineColor = Color.Black;
        chData.ChartAreas[0].CursorX.LineWidth = 1;
        chData.ChartAreas[0].CursorX.LineDashStyle = ChartDashStyle.Dot;
        chData.ChartAreas[0].CursorX.Interval = 0;
        chData.ChartAreas[0].CursorY.LineColor = Color.Black;
        chData.ChartAreas[0].CursorY.LineWidth = 1;
        chData.ChartAreas[0].CursorY.LineDashStyle = ChartDashStyle.Dot;
        chData.ChartAreas[0].CursorY.Interval = 0;

在图表的MouseMove事件处理程序中,可以执行以下操作以移动光标:

private void chData_MouseMove(object sender, MouseEventArgs e)
{
    Point mousePoint = new Point(e.X, e.Y);

    Chart.ChartAreas[0].CursorX.SetCursorPixelPosition(mousePoint, true);
    Chart.ChartAreas[0].CursorY.SetCursorPixelPosition(mousePoint, true);

    // ...
}

这是SetCursorPixelPosition方法的文档:

这正是我想要的!非常感谢,非常简洁明了的回答。