windowsforms-2509-controls-and-libraries-chart-control-examples-end-user-interaction-how-to-determine-which-chart-element-the-mouse-pointer-hovers-over.md
The following example handles the ChartControl.MouseMove event to identify the chart element under the mouse pointer and display its name in the form’s caption.
Note
Turn on the ChartControl.RuntimeHitTesting option to enable hit testing.
using DevExpress.XtraCharts;
using System.Windows.Forms;
namespace DXApplication {
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
public Form1() {
InitializeComponent();
chartControl1.MouseMove += ChartControl1_MouseMove;
chartControl1.RuntimeHitTesting = true;
}
void ChartControl1_MouseMove(object sender, MouseEventArgs e) {
ChartHitInfo hi = chartControl1.CalcHitInfo(new System.Drawing.Point(e.X, e.Y));
this.Text = hi.HitTest.ToString();
}
}
}
Imports DevExpress.XtraCharts
Imports System.Windows.Forms
Namespace DXApplication
Public Partial Class Form1
Inherits DevExpress.XtraEditors.XtraForm
Public Sub New()
InitializeComponent()
AddHandler chartControl1.MouseMove, AddressOf ChartControl1_MouseMove
chartControl1.RuntimeHitTesting = True
End Sub
Private Sub ChartControl1_MouseMove(sender As Object, e As MouseEventArgs)
Dim hi As ChartHitInfo = chartControl1.CalcHitInfo(New System.Drawing.Point(e.X, e.Y))
Me.Text = hi.HitTest.ToString()
End Sub
End Class
End Namespace
The following example obtains the name of the series under the mouse pointer and displays it in the form’s caption:
using DevExpress.XtraCharts;
using System.Windows.Forms;
namespace DXApplication {
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
public Form1() {
InitializeComponent();
chartControl1.MouseMove += ChartControl1_MouseMove;
chartControl1.RuntimeHitTesting = true;
}
void ChartControl1_MouseMove(object sender, MouseEventArgs e) {
ChartHitInfo hi = chartControl1.CalcHitInfo(new System.Drawing.Point(e.X, e.Y));
if(hi.HitTest == ChartHitTest.Series){
this.Text = ((Series)hi.Series).Name;
}
}
}
}
See Also
How to: Show Series Labels Only for Hot-tracked Points
How to: Determine which Series Point Is Under the Test Point