Chart for .NET / User's Guide / Interactivity / Drag Tools / Drag Tools Overview

In This Topic
    Drag Tools Overview
    In This Topic

    All drag operations inherit directly or indirectly from the NDragTool class, which suggests that they share a number of common features.

     Selection
    All drag tools depend on the current selection. As we mentioned in the Selection topic the selection can be modified both programmatically and visually (by the user).
     Events

    All drag tools raise the BeginDrag, DoDrag, EndDrag and Cancel events. Their meaning and paramters are described in the following table:

    Event Description Event argument
    BeginDrag Fired before a drag operation is about to begin. An object of type NDragEventArgs containg the mouse coordinates as well as the current key state.
    Drag Fired when a drag operation is being processed. An object of type NDragEventArgs containg the mouse coordinates as well as the current key state.
    EndDrag Fired after a drag operation has ended. An object of type NDragEventArgs containg the mouse coordinates as well as the current key state.
    Cancel Fired if the user pressed the Escape button. A null (Nothing in VB.NET) value.


    You subscribe to these events in the following manner:

    C#
    Copy Code
    someDragTool.BeginDrag += new EventHandler(OnSomeDragToolBeginDrag);
    someDragTool.EndDrag += new EventHandler(OnSomeDragToolEndDrag);
    someDragTool.Drag += new EventHandler(OnSomeDragToolDoDrag);
    someDragTool.Cancel += new EventHandler(OnSomeDragToolCancel);
    
    Visual Basic
    Copy Code
    AddHandler someDragTool.BeginDrag, AddressOf OnSomeDragToolBeginDrag
    AddHandler someDragTool.EndDrag, AddressOf OnSomeDragToolEndDrag
    AddHandler someDragTool.Drag, AddressOf OnSomeDragToolDoDrag
    AddHandler someDragTool.Cancel, AddressOf OnSomeDragToolCancel
    
     Cancelling Drag Operations
    All drag operations can be cancelled by the user when he/she presses the Esc key. In addition you can programmatically terminate a drag operation by calling the Cancel method of NDragTool class.
     Changing the Mouse Drag Button

    Most of the drag operations are activated when the user presses the left mouse button and drags the mouse over the chart. An exception to this is the NDataPanTool drag tool which is activated when the user presses the right mouse button key. You can control the mouse action that triggers the drag operation by modifying the BeginDragMouseCommand property of the NDragTool object. The following code will create a trackball tool activated when the user presses the right mouse button:

    C#
    Copy Code
    NTrackballTool trackballTool = new NTrackballTool();
    trackballTool.BeginDragMouseCommand = new NMouseCommand(MouseAction.Down, MouseButtons.Right, 1);
    
    chartControl.Controller.Tools.Add(trackballTool);
    
    Visual Basic
    Copy Code
    Dim trackballTool As New NTrackballTool
    trackballTool.BeginDragMouseCommand = New NMouseCommand(MouseAction.Down, MouseButtons.Right, 1)
    
    chartControl.Controller.Tools.Add(trackballTool)
    
     Changing the Mouse Cursor

    The mouse cursor associated with each drag operation can be modified with the help of the Cursor property of the NDragTool object:

    C#
    Copy Code
    someDragTool.Cursor = Cursors.Hand;
    
    Visual Basic
    Copy Code
    someDragTool.Cursor = Cursors.Hand
    
    See Also