目标
1、鼠标移到线段上方,该段线段高亮
步骤(在之前代码基础之上)
1、实现chart的mousemove事件,代码如下
private void chart1_MouseMove(object sender, MouseEventArgs e) { // Call HitTest HitTestResult result = chart1.HitTest(e.X, e.Y); // Reset Data Point Attributes foreach (DataPoint point in chart1.Series[0].Points) { point.BackSecondaryColor = Color.Black; point.BackHatchStyle = ChartHatchStyle.None; point.BorderWidth = 1; } // If the mouse if over a data point if (result.ChartElementType == ChartElementType.DataPoint) { // Find selected data point DataPoint point = chart1.Series[0].Points[result.PointIndex]; // Change the appearance of the data point point.BackSecondaryColor = Color.White; point.BackHatchStyle = ChartHatchStyle.Percent25; point.BorderWidth = 2; } else { // Set default cursor this.Cursor = Cursors.Default; } }
2、效果如下
首先,窗体刚启动,如下
鼠标移动上,效果如下