views:

56

answers:

1

Hello all

I am performing a drag-and-drop operation of an anchor text selected in a browser window onto an app created in C#.

Consider this link

<a href="http://www.google.com"&gt;Google Me</a>

In case of IE browsers...

When I select the anchor text "Google Me" and drop it onto my application, the text dropped is "Google Me".

In case of Chrome, Firefox, Safari....

On doing the same operation the text dropped is "http://www.google.com".

I tried doing this on some other apps as well like Notepad++, Eclipse, there also the same thing occurred. In some other apps, like Thunderbird, drag-and-drop from IE was same, from others, formatted anchor link got dropped.

Is this about the implementation of drag-and-drop operation that is different in various browsers? If not, can the drag-and-drop implementation be changed in the application where the text is being dropped?

I am a complete novice in C# and have no idea how the drag-and-drop operation is implemented. Just got curious with this.

Regards

+1  A: 

When you drag and drop, the source application supplies the data object and that gets put into the system clipboard so that target app (where drop would occur) could get the data. The actual data format is controlled by the source application and cannot be changed. For easier interoperability, there are some known data formats and source application may choose to support multiple formats besides its native data format. So it would provide some conversion to supported data format from native format. So in your case, you are probably asking for text data format and source app would either give link text or anchor text based on its implementation. Try using html format (e.Data.GetData(DataFormats.Html) and you may get consistent results.

Edit: To answer other part of your question, many target applications such as various editors would look at clipboard data and inquire for various formats that they support and they will choose the richest data format that they support. For exmaple, word would give preference to rtf (formatted text) over plain text and so on. Some applications would know about native formats of some popular program so that they can support drag & drop from such applications (as a feature).

VinayC