What's the simplest way to embed (new) file information in a drag?
I want users to be able to drag elements fr开发者_开发问答om my program onto the desktop to create files from them. What's the simplest way to embed this information into a DataObject so explorer will accept drops and create the appropriate file(s)?
My experience with drag and drop is limited, and so far the only way I can think of is to actually create the files in a temporary directory and attach their paths to the DataObject via a DataFormat of "FileDrop"... but there must be a better way.
Basically what I understand you want to do is drag a non-existent file from your application to explorer and have a physical file created.
Well, your solution of creating a temporary file and then setting that in the DataObject is probably the short cut solution.
The "correct" solution, without creating a temporary disk file will require significant amount of P/Invoke type interop to create a custom IDataObject that can render the file descriptor and content from memory rather than a physical source file. I have not done this in .NET, but I can guess it would be a fair amount of work.
精彩评论