Drag and Drop Into Word
-
I have all the code necessary (I think) to perform a drag and drop into word... but I am having trouble with pictures... any kind of Bitmap or Image does not drop properly into word, it does something but then acts as if I didn't drop anything it understood.... However, the same code works for dragging and dropping onto other office apps (e.g. Excel and Powerpoint). The code looks like this:
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (_mouseIsDown) { IDataObject obj = new DataObject(DataFormats.Bitmap, pictureBox1.Image); this.DoDragDrop(obj, DragDropEffects.All); } }
Any one have any idea what I'm doing wrong? (and for the record, I have tried it without using IDataObject as well, just directly putting the image into the data argument... oh and I also tried creating a "new Bitmap(pictureBox1.Image)" and putting that in the data argument... To no avail.... A) Can anyone reproduce the issue at hand B) Does anyone know what I'm doing wrong? Do I need to use OLE directly or something? Thanks Chadwick Posey============================= I'm a developer, he's a developer, she's a developer, we're developers, Wouldn't ya like to be a developer too?
-
I have all the code necessary (I think) to perform a drag and drop into word... but I am having trouble with pictures... any kind of Bitmap or Image does not drop properly into word, it does something but then acts as if I didn't drop anything it understood.... However, the same code works for dragging and dropping onto other office apps (e.g. Excel and Powerpoint). The code looks like this:
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (_mouseIsDown) { IDataObject obj = new DataObject(DataFormats.Bitmap, pictureBox1.Image); this.DoDragDrop(obj, DragDropEffects.All); } }
Any one have any idea what I'm doing wrong? (and for the record, I have tried it without using IDataObject as well, just directly putting the image into the data argument... oh and I also tried creating a "new Bitmap(pictureBox1.Image)" and putting that in the data argument... To no avail.... A) Can anyone reproduce the issue at hand B) Does anyone know what I'm doing wrong? Do I need to use OLE directly or something? Thanks Chadwick Posey============================= I'm a developer, he's a developer, she's a developer, we're developers, Wouldn't ya like to be a developer too?
Welp this is as close as I could figure out. You cannot do it directly in memory (as far as I can tell), but here is the code emulating something close to dragging and dropping a file from explorer into word:
string[] files = new string[1]; files[0] = @"C:\someimage.jpg"; IDataObject d = new DataObject(); d.SetData(DataFormats.FileDrop, files); if (this.DoDragDrop(d, DragDropEffects.Copy) == DragDropEffects.Copy) { //your drop succeeded }
Still cannot figure out why I cannot just drag and drop an image directly though.... would love to know what I could do differently.============================= I'm a developer, he's a developer, she's a developer, we're developers, Wouldn't ya like to be a developer too?