Drag Drop from .NET application to Explorer
Asked Answered
R

2

11

I'm looking to provide users with ability to drag&drop files from grids and other controls in my application into Explorer. Any good samples/articles for that?

Rentsch answered 3/8, 2010 at 17:22 Comment(1)
Here is some information from the microsoft forums social.msdn.microsoft.com/forums/en-US/winforms/thread/…. I did find a bunch of relevant articles searching with the title of this postPostmillennialism
W
8

It's pretty straight-forward, just call DoDragDrop in a MouseDown event. You'll need actual files on disk for this to work.

private void Form1_MouseDown(object sender, MouseEventArgs e) { 
   string[] files = new string[] { @"c:\temp\test.txt" };
   this.DoDragDrop(new DataObject(DataFormats.FileDrop, files), DragDropEffects.Copy); 
}
Wickliffe answered 3/8, 2010 at 18:50 Comment(2)
This method works perfectly except that it interferes with other events like double click item and click and drag to multi-select. Is there a way to solve this?Quadri
Sure, use the MouseMove event instead and don't start the drag until it moved far enough. Not the topic of this question.Wickliffe
H
1

Here is a sample application but it cannot handle large files: Transferring Virtual Files to Windows Explorer in C#

Haggi answered 3/8, 2010 at 17:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.