Started out with a "C# drag drop" Google. First thing that came up was a six-year-old article from C-Sharp Corner. Was a simple file brower example that was pretty hard to follow. It was dated information anyway.
There was a very succint Microsoft knowledge base article that was more helpful. The example is doing something akin to what I'm looking to do: receiving a file or files dragged from elsewhere onto a listbox. It was pretty easy to put together and worked on first compile. Dropping an image from IE or Firefox over the list box would show the full path to the image's temporary file.
I wondered what else would be available so I went to the definition of DataFormats—there were twenty-one! They reminded me of clip board data types. Went to the MSDN summary and it covers how to create your own format for use on the clipboard.
Next I was wondering if I could access those other types. From the way I see Paste Special work in Microsoft applications, I suspected that the clipboard could make data available in multiple formats (unless they parse a rich source in your selected way). I was hoping the HTML format might include the URL source of the image I was dragging.
So I added another list box I called lstFormat and added the following code to the DragDrop event:
GetFormats has an overload that I specified false initially. By setting it to true, I got a larger list of all formats the source could be converted to. Very handy.lstFormat.Items.Clear();
String[] formats = (string[])e.Data.GetFormats(false);
foreach (String format in formats)
{
lstFormat.Items.Add(format);
}
Now I need to spend some time figuring out how to work with these other formats.
No comments:
Post a Comment