All drag operations inherit directly or indirectly from the DragOperation class and as a result share a number of common features.
Events
All drag operations fire the BeginDrag, DoDrag, EndDrag and Cancel events. Their meaning and parameters are described in the following table:
Event |
Description |
Event argument |
BeginDrag |
Fired before a drag operation is about to begin. |
An object of type DragEventArgs containing the mouse coordinates as well as the current key state. |
DoDrag |
Fired when a drag operation is being processed. |
An object of type DragEventArgs containing the mouse coordinates as well as the current key state. |
EndDrag |
Fired after a drag operation has ended. |
An object of type DragEventArgs containing the mouse coordinates as well as the current key state. |
Cancel |
Fired if the user presses the Escape button. |
A null (Nothing in VB.NET) value. |
You subscribe to these events in the following manner:
VB.NET |
|
AddHandler someDragTool.BeginDrag, AddressOf OnSomeDragToolBeginDrag AddHandler someDragTool.EndDrag, AddressOf OnSomeDragToolEndDrag AddHandler someDragTool.DoDrag, AddressOf OnSomeDragToolDoDrag AddHandler someDragTool.Cancel, AddressOf OnSomeDragToolCancel
|
C# |
|
someDragTool.BeginDrag += new EventHandler(OnSomeDragToolBeginDrag); someDragTool.EndDrag += new EventHandler(OnSomeDragToolEndDrag); someDragTool.DoDrag += new EventHandler(OnSomeDragToolDoDrag); someDragTool.Cancel += new EventHandler(OnSomeDragToolCancel);
|
Cancelling drag operations
All drag operations can be cancelled by the end-user when the Esc key is pressed. In addition, you can terminate a drag operation by calling the virtual CancelOperation method of DragOperation class.
Changing the mouse drag button
Most of the drag operations are activated when the end-user presses the left mouse button and drags the mouse over the chart. An exception to this is the DataPanTool drag operation, which is activated when the end-user presses the right mouse button. You can control the mouse button that triggers the drag operation by modifying the MouseDragButton property of the DragOperation object:
VB.NET |
|
someDragTool.MouseDragButton = MouseButtons.Right |
C# |
|
someDragTool.MouseDragButton = MouseButtons.Right; |
Changing the mouse cursor
The mouse cursor associated with each drag operation can be modified through the Cursor property of the DragOperation object:
VB.NET |
|
someDragTool.Cursor = Cursors.Hand |
C# |
|
someDragTool.Cursor = Cursors.Hand; |