Search code examples
c#windowsdrag-and-dropwindows-explorer

Drag & Drop from Windows Explorer into my application’s TextBox


Why is the dragdrop event never entered?

private void textBox1_DragDrop(object sender, DragEventArgs e)
{
    Array a = (Array)e.Data.GetData(DataFormats.FileDrop);

    e.Effect = DragDropEffects.All;
    Debug.WriteLine("were in dragdrop");
}

private void textBox1_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
    {
        e.Effect = DragDropEffects.All;
    }
}

Solution

  • Change the e.Effect assignment to DragDropEffects.Copy. Double-check that the event assignment is still there, click the lightning bolt icon in the Properties window. Sample code is available in this thread. Note that you can cast to string[] directly.