MxLDevs
MxLDevs

Reputation: 19546

Dragging objects from one application to another

I have two small applications: an image file explorer, and an image viewer.

The explorer uses a standard tree view to display contents from the file system.
The viewer supports drag and drop to load files.

I want to drag a file entry from my explorer into my viewer and have it load the image. Each node in the explorer holds a FileInfo object in its tag if I need to access specific info.

Is this possible?

Note: I can build the viewer directly into the explorer, but I wanted to see whether I can drag objects both in and out of an application.

Upvotes: 0

Views: 1458

Answers (1)

Les
Les

Reputation: 10605

Some basic code to take data from your custom app...

DataObject d = new DataObject(); 
d.SetData(DataFormats.Serializable, myObject); 
myForm.DoDragDrop(d, DragDropEffects.Copy); 

You typically start by identifying the source of your drag, UIElement or ContentElement and create a handler for the MouseMove event. That is where the above code should go.

On your drop target, you also identify the element, set AllowDrop to true, and implement the Drop event handler. Take a look at Drag and Drop Overview which should be very helpful.

Upvotes: 1

Related Questions