Control.DragDrop Event

Occurs when a drag-and-drop operation is completed.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

public event DragEventHandler DragDrop
/** @event */
public void add_DragDrop (DragEventHandler value)

/** @event */
public void remove_DragDrop (DragEventHandler value)

JScript supports the use of events, but not the declaration of new ones.

The X and Y properties of the DragEventArgs are in screen coordinates, not client coordinates. The following line of Visual C# code converts the properties to a client Point.

Point clientPoint = targetControl.PointToClient(new Point(de.X, de.Y));

In versions earlier than Microsoft .NET Framework version 2.0, if you put a UserControl with DragEnter and DragDrop events on a Windows Form and drag and drop something onto the UserControl at design time, the DropDrop and DropEnter events are raised. However, when you close and reopen the solution, the DragEnter and DragDrop events are not raised again.

For more information about handling events, see Consuming Events.

The following code example demonstrates a drag-and-drop operation between two ListBox controls. The example calls the DoDragDrop method when the drag action starts. The drag action starts if the mouse has moved more than SystemInformation.DragSize from the mouse location during the MouseDown event. The IndexFromPoint method is used to determine the index of the item to drag during the MouseDown event.

The example also demonstrates using custom cursors for the drag-and-drop operation. The example requires that two cursor files, 3dwarro.cur and 3dwno.cur, exist in the application directory, for the custom drag and no-drop cursors, respectively. The custom cursors will be used if the UseCustomCursorsCheckCheckBox is checked. The custom cursors are set in the GiveFeedback event handler.

The keyboard state is evaluated in the DragOver event handler for the right ListBox, to determine what the drag operation will be based on state of the SHIFT, CTRL, ALT, or CTRL+ALT keys. The location in the ListBox where the drop would occur is also determined during the DragOver event. If the data to drop is not a String, then the DragEventArgs.Effect is set to a value of None in DragDropEffects. Finally, the status of the drop is displayed in the DropLocationLabelLabel.

The data to drop for the right ListBox is determined in the DragDrop event handler and the String value is added at the appropriate place in the ListBox. If the drag operation moves outside the bounds of the form, then the drag-and-drop operation is canceled in the QueryContinueDrag event handler.

This code excerpt demonstrates using the DragDrop event. See the DoDragDrop method for the complete code example.

private void ListDragTarget_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) 
    // Ensure that the list item index is contained in the data.
    if (e.Data.GetDataPresent(typeof(System.String))) {

        Object item = (object)e.Data.GetData(typeof(System.String));

        // Perform drag-and-drop, depending upon the effect.
        if (e.Effect == DragDropEffects.Copy ||
            e.Effect == DragDropEffects.Move) {
            // Insert the item.
            if (indexOfItemUnderMouseToDrop != ListBox.NoMatches)
                ListDragTarget.Items.Insert(indexOfItemUnderMouseToDrop, item);
    // Reset the label text.
    DropLocationLabel.Text = "None";

private void listDragTarget_DragDrop(Object sender, 
    System.Windows.Forms.DragEventArgs e)
    // Ensure that the list item index is contained in the data.
    if (e.get_Data().GetDataPresent(String.class.ToType())) {
        Object item = (Object)(e.get_Data().GetData(
        // Perform drag-and-drop, depending upon the effect.
        if (e.get_Effect().Equals(DragDropEffects.Copy) || 
            e.get_Effect().Equals(DragDropEffects.Move)) {
            // Insert the item.
            if (indexOfItemUnderMouseToDrop != ListBox.NoMatches) {
                    indexOfItemUnderMouseToDrop, item);
            else {
    // Reset the label text.
} //listDragTarget_DragDrop

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions