This documentation is archived and is not being maintained.

Control.DragDrop Event

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

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

Public Event DragDrop As DragEventHandler
Dim instance As Control 
Dim handler As DragEventHandler 

AddHandler instance.DragDrop, handler

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 .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.

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

Private Sub ListDragTarget_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles ListDragTarget.DragDrop
    ' Ensures that the list item index is contained in the data. 

    If (e.Data.GetDataPresent(GetType(System.String))) Then 

        Dim item As Object = CType(e.Data.GetData(GetType(System.String)), System.Object)

        ' Perform drag-and-drop, depending upon the effect. 
        If (e.Effect = DragDropEffects.Copy Or _
            e.Effect = DragDropEffects.Move) Then 

            ' Insert the item. 
            If (indexOfItemUnderMouseToDrop <> ListBox.NoMatches) Then
                ListDragTarget.Items.Insert(indexOfItemUnderMouseToDrop, item)

            End If 
        End If 
        ' Reset the label text.
        DropLocationLabel.Text = "None" 
    End If 
End Sub

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0