Control.DragDrop 이벤트

정의

끌어서 놓기 작업이 완료될 때 발생합니다.

public:
 event System::Windows::Forms::DragEventHandler ^ DragDrop;
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 . 참조 된 DoDragDrop 전체 코드 예제에 대 한 메서드.

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, DragEventArgs e)
{
    // Ensure that the list item index is contained in the data.
    if (e.Data.GetDataPresent(typeof(System.String)))
    {
        Object item = 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

설명

DragEventArgsY 속성은 X 클라이언트 좌표가 아닌 화면 좌표에 있습니다. 다음 Visual C# 코드 줄은 속성을 클라이언트 Point로 변환합니다.

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

참고

.NET Framework 2.0 이전 버전에서 Windows Form에 with DragEnter 및 이벤트를 넣고 UserControl 디자인 타임 DropDrop 에 무언가를 끌어서 UserControl 놓으면 및 DropEnterDragDrop 이벤트가 발생합니다. 그러나 솔루션을 DragEnter 닫았다가 다시 열면 및 DragDrop 이벤트가 다시 발생하지 않습니다.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.

적용 대상

추가 정보