System.Windows.Forms.Control.DoDragDrop Method

Begins a drag-and-drop operation.

Syntax

public DragDropEffects DoDragDrop (object data, DragDropEffects allowedEffects)

Parameters

data
The data to drag.
allowedEffects
One of the System.Windows.Forms.DragDropEffects values.

Returns

A value from the System.Windows.Forms.DragDropEffects enumeration that represents the final effect that was performed during the drag-and-drop operation.

Remarks

The allowedEffects parameter determines which drag operations can occur. If the drag operation needs to interoperate with applications in another process, data should either be a base managed class (string, System.Drawing.Bitmap, or System.Drawing.Imaging.Metafile), or an object that implements System.Runtime.Serialization.ISerializable or System.Windows.Forms.IDataObject.

The following describes how and when events related to drag-and-drop operations are raised.

The Control.DoDragDrop(object, DragDropEffects) method determines the control under the current cursor location. It then checks to see if the control is a valid drop target.

If the control is a valid drop target, the Control.GiveFeedback event is raised with the drag-and-drop effect specified. For a list of drag-and-drop effects, see the System.Windows.Forms.DragDropEffects enumeration.

Changes in the mouse cursor position, keyboard state, and mouse button state are tracked.

  • If the user moves out of a window, the Control.DragLeave event is raised.

  • If the mouse enters another control, the Control.DragEnter for that control is raised.

  • If the mouse moves but stays within the same control, the Control.DragOver event is raised.

If there is a change in the keyboard or mouse button state, the Control.QueryContinueDrag event is raised and determines whether to continue the drag, to drop the data, or to cancel the operation based on the value of the QueryContinueDragEventArgs.Action property of the event's System.Windows.Forms.QueryContinueDragEventArgs.

Note:

The Control.DoDragDrop(object, DragDropEffects) method catches all exceptions and rethrows only the following security or critical exceptions:

  • SecurityException

  • NullReferenceException

  • StackOverflowException

  • OutOfMemoryException

  • ThreadAbortException

  • ExecutionEngineException

  • IndexOutOfRangeException

  • AccessViolationException

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0