I've got a program that requires that the user pick a file or folder on their computer. Currently the user clicks Open Single in the File menu and an openFileDialog comes up; to open a folder the user clicks Batch from the File menu and an folderBrowserDi alog comes up. I'd like to expand this to allow the user to simply drag a file or folder onto the program window, and I'm realizing how complicated drag n drop can be.
I'm starting by just testing folders. I've set up an event handler for the dragEnter and dragLeave events. When I drag a folder over the form the dragOver event handler confirms that the data being dragged is actually a folder and returns either true or false. The dragLeave handler then displays all the files in that folder when I let go of the mouse. The problem here is that while letting go of the mouse completes the drag and drop, so does dragging my mouse outside the form's bounds. I need a way to confirm that the data was actually dropped onto the form.
I've tried the DragDrop event, but it doesn't seem to do anything. I tried this simple code:
then I tried dropping something onto the form. Nothing happened. I didn't get a messagebox, nothing.
So how can I get the program to only process the information if the data was actually dropped onto the form, and not if it was dragged onto then out of the form?
I'm starting by just testing folders. I've set up an event handler for the dragEnter and dragLeave events. When I drag a folder over the form the dragOver event handler confirms that the data being dragged is actually a folder and returns either true or false. The dragLeave handler then displays all the files in that folder when I let go of the mouse. The problem here is that while letting go of the mouse completes the drag and drop, so does dragging my mouse outside the form's bounds. I need a way to confirm that the data was actually dropped onto the form.
I've tried the DragDrop event, but it doesn't seem to do anything. I tried this simple code:
Code:
private void Form1_DragDrop(object sender, DragEventArgs e)
{
MessageBox.Show("Data was dropped");
}
So how can I get the program to only process the information if the data was actually dropped onto the form, and not if it was dragged onto then out of the form?
Comment