Control.DragDrop Control.DragDrop Control.DragDrop Control.DragDrop Event

정의

끌어서 놓기 작업이 완료될 때 발생합니다.Occurs when a drag-and-drop operation is completed.

public:
 event System::Windows::Forms::DragEventHandler ^ DragDrop;
public event System.Windows.Forms.DragEventHandler DragDrop;
member this.DragDrop : System.Windows.Forms.DragEventHandler 
Public Custom Event DragDrop As DragEventHandler 

예제

이 코드 예제에서는 사용 하 여는 DragDrop 이벤트입니다.This code excerpt demonstrates using the DragDrop event. 참조 된 DoDragDrop 전체 코드 예제에 대 한 메서드.See the DoDragDrop method for the complete code example.

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( System::String::typeid ) )
   {
      Object^ item = dynamic_cast<Object^>(e->Data->GetData( System::String::typeid ));
      
      // 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 );
         else
                        ListDragTarget->Items->Add( 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.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);
            else
                ListDragTarget.Items.Add(item);
            
        }
    }
    // Reset the label text.
    DropLocationLabel.Text = "None";
}
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)
            Else
                ListDragTarget.Items.Add(item)

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

설명

합니다 XY 의 속성을 DragEventArgs 클라이언트 좌표가 아닌 화면 좌표에 합니다.The X and Y properties of the DragEventArgs are in screen coordinates, not client coordinates. Visual C# 코드의 다음 줄을 클라이언트에 속성을 변환 Point합니다.The following line of Visual C# code converts the properties to a client Point.

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

참고

버전에서 이전의 .NET Framework 2.0.NET Framework 2.0을 추가한 경우는 UserControl 사용 하 여 DragEnterDragDrop Windows Form에 이벤트 끌어서 특정 항목에 UserControl 디자인 타임에 DropDropDropEnter 이벤트는 발생합니다.In versions earlier than .NET Framework 2.0.NET Framework 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. 그러나 닫았다가 솔루션을 다시 합니다 DragEnterDragDrop 이벤트가 다시 발생 하지 않습니다.However, when you close and reopen the solution, the DragEnter and DragDrop events are not raised again.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.For more information about handling events, see Handling and Raising Events.

적용 대상

추가 정보