2

I have a WPF user control hosted in a Windows Forms Application and the control contains a WPF image ( among other things ) and was wondering whether it is possible to let the user drag this image to outside the app ( to windows explorer, to the desktop , to a folder) ?

Regards, MadSeb

MadSeb
  • 7,958
  • 21
  • 80
  • 121
  • Drag what to the desktop? Do you mean to make it the background image, or to drag and drop a file on the desktop? – Wonko the Sane Sep 21 '10 at 14:34
  • Hi .. I meant to say drag and drop the file outside the app. ( this can be a drag and drop from the app to the desktop, to a folder or to windows explorer ) – MadSeb Sep 21 '10 at 14:40

1 Answers1

1

It is possible - when you start the drag/drop operation (DoDragDrop), you pass in a IDataObject - this is the key to allowing what you want.

The easy way to do this is to use a normal DataObject with DataFormats.FileDrop, and give it the name of the file. Unfortunately this is not quite what you want, but the quick and dirty way for you to do this would be to create a temporary file and pass that as the name. Done.

The hard way is to implement IDataObject and serve up a virtual (in-memory) file containing the image you want. There is an article on codeplex about transferring virtual files to windows explorer via drag-drop that should get you started. Also see Drag and drop virtual files using IStream

Community
  • 1
  • 1
Philip Rieck
  • 32,368
  • 11
  • 87
  • 99