Drag and drop

How to implement drag and drop between my program and ya explorer for windows only

+4
source share
3 answers

While you are using WinForms, it is really very simple. See these two articles to get you started:

And just in case, when you use WPF, this tutorial and this SO thread should help.

+5
source

CodeProject has a good article on how to do this:

This sample project lists the folder full of files, and allows you to drag and drop them into Explorer. You can also drag the wire into the sample, and you can use Shift and Ctrl to change the action, just like in the wire.

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

To start a drag operation in Explorer, we implement an ItemDrag event from a Listview that receives more than a few pixels after dragging an item. We just call DoDragDrop the file transfer is dragged into the DataObject . You really don't need to understand DataObject - it implements the IDataObject Interface used in communication.

+1
source

Add this to the drag enter event (this will change the type of cursor when dragging the 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 in the DragDrop event you need to handle what needs to be done. And also set the AllowDrop property to true

+1
source

All Articles