views:

398

answers:

3
+3  Q: 

Drag and Drop

How to Implement Drag and Drop Between my Program and Explorer ya windows application only

+1  A: 

There is a good article on CodeProject about how to do this:

This sample project lists a folder full of files, and lets you drag and drop them into Explorer. You can also drag from Explorer into the sample, and you can use the Shift and Ctrl keys to modify the action, just like in Explorer.

Drag and drop, cut/copy and paste files with Windows Explorer

To start a drag operation into Explorer, we implement the ItemDrag event from the Listview, which gets called after you drag an item more than a few pixels. We simply call DoDragDrop passing the files to be dragged wrapped in a DataObject. You don't really need to understand DataObject - it implements the IDataObject interface used in the communication.

splattne
+4  A: 

As long as you're using WinForms, it's actually very straightforward. See these two articles to get you started:

And just in case you're using WPF, this tutorial and this SO thread should help.

Noldorin
A: 

Add this on the Drag enter event (this will change the cursor type when you are dragging a file)

 private void Form1_DragEnter(object sender, DragEventArgs e)
    {
        // If file is dragged, show cursor "Drop allowed"
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
            e.Effect = DragDropEffects.Copy;
        else
            e.Effect = DragDropEffects.None;
    }

Then on the DragDrop event you need to handle what do ou want to do. And also set the AllowDrop property to true

Quaky