Reputation: 2842
How to Implement Drag and Drop Between my Program and Explorer ya windows application only
Upvotes: 4
Views: 3811
Reputation: 147240
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.
Upvotes: 5
Reputation: 1601
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
Upvotes: 1
Reputation: 104030
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 theListview
, which gets called after you drag an item more than a few pixels. We simply callDoDragDrop
passing the files to be dragged wrapped in aDataObject
. You don't really need to understandDataObject
- it implements theIDataObject
interface used in the communication.
Upvotes: 1