Drag And Drop To Word

J

John Smith

Hi folks,

I've got a C# Windows Form Application that I'm trying to allow Drag And
Drop into Office with. I can Drag And Drop text no problem. However, when I
Drag And Drop an Image into Word, the image doesn't get added to the
document...nothing happens. If I do Drag it into PowerPoint, it works fine
and the image is added.

I've read about some work arounds (as I'm not the only one to experience
this) that use the Clipboard, however that is not an option for us.

Does anyone know how to allow dragging and dropping of images into Word?
Again, it works fine in PowerPoint.

Here's the code I'm using:
Image img = Image.FromFile("C:\\MyImage.bmp");
lblDragDropTest.DoDragDrop(img, DragDropEffects.Copy);

(Using the Bitmap instead of the image object doesn't work either)

Thanks!
 
J

John Smith

Answered my own question. A friend of mine found a sample code of passing
rtf code as drag and drop to Word in order to drop a Bookmark into the
document. Then it occured to me that I could probably pass rtf code that
contains an image and pass that. Sure enough...It worked.

Here's what to do...Open Word Pad. Drag and Drop your image into Word Pad
(and nothing but the image). Save the document as rtf. Close it and open
the document in Notepad. Notepad will display all the rtf data. Copy and
Paste all the rtf data and then, for your drag drop, do:

string rtfcode = @"rtfcode goes here";
object rtfDropData = new DataObject(DataFormats.Rtf, rtfcode);
YourControl.DoDragDrop(rtfDropData, DragDropEffects.Copy);

Now when you drag and drop the rtf data into word, your image will appear
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top