I’d like to be able to drag a file/executable/shortcut into a Windows Forms application and have the application determine the original path of the dropped file then return it as a string.
E.g. drag an image from the desktop into the application and messagebox up the local path of the image.
Is that possible? Could someone provide me with an example maybe?
It’s quite easy. Just enable drap-and-drop by setting the
AllowDropproperty toTrueand handle theDragEnterandDragDropevents.In the
DragEnterevent handler, you can check if the data is of the type you want using theDataFormatsclass.In the
DragDropevent handler, use theDataproperty of theDragEventArgsto receive the actual data and theGetDatamethodExample: