Xceed Chart for WinForms v4.4 Documentation
Welcome to Xceed Chart for WinForms v4.4 / User Guide / Interactivity / Events
In This Topic
    Events
    In This Topic

    Xceed Chart for WinForms has extensive support for tracking mouse events that occur when the end-user moves or clicks with the mouse over the control. 

    Working with events is very easy and straightforward. The following table lists the available delegates (see MouseAction Enumeration for more details): 

    Delegate name Delegate type Description
    MouseMove System.Windows.Forms.MouseEventHandler

    Occurs when the mouse pointer is moved over the control. The event handler receives an argument of type System.Windows.Forms.MouseEventArgs containing data related to this event.

    MouseDown System.Windows.Forms.MouseEventHandler

    Occurs when the mouse pointer is over the control and a mouse button is pressed. The event handler receives an argument of type System.Windows.Forms.MouseEventArgs containing data related to this event.

    MouseUp System.Windows.Forms.MouseEventHandler

    Occurs when the mouse pointer is over the control and a mouse button is released. The event handler receives an argument of type System.Windows.Forms.MouseEventArgs containing data related to this event.

    MouseHover System.EventHandler Occurs when the mouse pointer hovers over the control. This event is preceded by a MouseMove event.
    MouseWheel System.Windows.Forms.MouseEventHandler

    Occurs when the mouse wheel moves while the control has focus. The event handler receives an argument of type System.Windows.Forms.MouseEventArgs containing data related to this event.

    MouseEnter System.EventHandler Occurs when the mouse pointer enters the control.
    MouseLeave System.EventHandler Occurs when the mouse pointer leaves the control.

    As you can see, handling chart events is much like handling normal Windows Forms events. For event handlers of type System.Windows.Forms.MouseEventHandler, the ChartControl's HitTest method is used to get information about the object under the mouse cursor by passing it the coordinates received through the MouseEventArgs. Event handlers of type System.EventHandler refer to the ChartControl as a whole; therefore, the HitTest method is not used. 

    Let's take a look at a real example demonstrating how to use MouseDown:

    C#  
    private void Form_Load(object sender, System.EventArgs e)
    {
    Chart chart = (Chart)chartControl1.Charts.GetAt(0);

    chartControl1.Background.FillEffect.SetGradient(GradientStyle.DiagonalDown, GradientVariant.Variant3, Color.Thistle, Color.White);

    PieSeries pie = (PieSeries)chart.Series.Add(SeriesType.Pie);
    pie.AddPie(12, 0, "Cars", new FillEffect(Color.Red), new LineProperties());
    pie.AddPie(42, 0, "Trains", new FillEffect(Color.Gold), new LineProperties());
    pie.AddPie(56, 0, "Airplanes", new FillEffect(Color.Chocolate), new LineProperties());
    pie.AddPie(23, 0, "Buses", new FillEffect(Color.Cyan), new LineProperties());
    pie.Appearance.FillMode = AppearanceFillMode.DataPoints;
    pie.Legend.Mode = SeriesLegendMode.DataPoints;
    pie.Legend.Format = "<label> <percent>";

    // subscribe for on mouse down
    chartControl1.MouseDown += new System.Windows.Forms.MouseEventHandler(OnMouseDown);
    }

    private void OnMouseDown(object sender, MouseEventArgs e)
    {
    MessageBox.Show("A mouse-down event was generated.");
    }

    Related Examples

    Windows Forms: Interactivity\Mouse Events 

    Web Forms: Getting started\HTML image map, Getting started\HTML image map postback

    See Also

    ChartControl | SeriesInteractivity | Interactivity | HTML Image Map | HTML Image Map with Postback