Back to Devexpress

How to: Determine whether an Axis Title is Being Hovered by the Mouse Pointer

windowsforms-7001-controls-and-libraries-chart-control-examples-chart-elements-how-to-determine-whether-an-axis-title-is-being-hovered-by-the-mouse-pointer.md

latest2.2 KB
Original Source

How to: Determine whether an Axis Title is Being Hovered by the Mouse Pointer

  • Oct 02, 2023

This example demonstrates how you can determine whether an axis title is being hovered by the mouse pointer, and if so, display its type (AxisTitleX or AxisTitleY) in a tooltip.

csharp
using DevExpress.XtraCharts;
using System;
using System.Windows.Forms;

namespace AxisTitleHitTestSample {
    public partial class SampleForm : Form {
        public SampleForm() {
            InitializeComponent();
        }

        private void OnMouseMove(object sender, MouseEventArgs e) {
            ChartHitInfo hitInfo = chart.CalcHitInfo(e.X, e.Y);
            if (hitInfo.AxisTitle != null)
                tooltipController.ShowHint(
                    String.Format(
                        "The pointer is over the {0} object.", 
                        hitInfo.AxisTitle.GetType().ToString()
                    )
                );
            else
                tooltipController.HideHint();
        }
    }
}
vb
Imports DevExpress.XtraCharts
Imports System
Imports System.Windows.Forms

Namespace AxisTitleHitTestSample
    Partial Public Class SampleForm
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Overloads Sub OnMouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles chart.MouseMove
            Dim hitInfo As ChartHitInfo = chart.CalcHitInfo(e.X, e.Y)
            If hitInfo.AxisTitle IsNot Nothing Then
                tooltipController.ShowHint(String.Format("The pointer is over the {0} object.", hitInfo.AxisTitle.GetType().ToString()))
            Else
                tooltipController.HideHint()
            End If
        End Sub
    End Class
End Namespace

The result is shown in the following image.

See Also

Axis Titles