Trap drag drop into word in c#

B

Brent Kurdydyk

Hi all, just wondering if anyone has a method for trapping a drag/drop in
word? I'm hosting word in a browser control on a c# winform. The desired
result I am trying to achieve is to give users the ability to drag and drop
fields or bookmarks into word.

tia,
Brent
 
P

Peter Huang

Hi Brent,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you have a C# winforms application
with a webbrowser control, you will use the webbrowser control to open a
word document.
After that you hope to Drag&Drop fields and bookmark into word. But I am
confusion where will you drag the fields and bookmark into word.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Based on my knowledge, the Word object modal does not allow us to handle
the drag&drop of word, it will handle the stuff itself.
Here I write some code snippet which will drag the text of a lable into the
word document host in a webbrowser.
private void Form1_Load(object sender, System.EventArgs e)
{
object o = Missing.Value;
//open a word document
this.axWebBrowser1.Navigate(@"C:\Test.doc",ref o,ref o,ref o,ref o);
//handle the mousedown event of label1 to enable drag
this.label1.MouseDown +=new MouseEventHandler(label1_MouseDown);
}
private void label1_MouseDown(object sender, MouseEventArgs e)
{
this.label1.DoDragDrop(this.label1.Text,DragDropEffects.Copy);
}


Run the windows form application and drag the text of the label and drop
into the word, the text of the label will be copied into word document.

Please apply my suggestion above and let me know if it helps resolve your
problem.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
B

Brent Kurdydyk

Thanks for the response. I got it working well now. Basically I have a list
box of "fields and bookmarks" on the form, and I am dragging the items from
the list box onto the word doc (hosted in the browser control). In order to
accomplish this, I am using a dataobject instead of just dragging the text.
Here is a bit of code:

string theData = @"{\rtf1 {\*\bkmkstart myBookMark}This is a
bookmark{\*\bkmkend myBookMark} }";

object theDropData = new DataObject(DataFormats.Rtf,theData);

ListBoxTags.DoDragDrop(theDropData,DragDropEffects.Copy);

The key to getting this to work is setting the string value (theData) to be
valid rtf string...valid rtf and valid for ms word.



Brent.
 
P

Peter Huang

Hi Brent,

I am glad that you have resolved that problem.
Thank you very much for sharing the knowledge in the community.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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