I added a functionality to my C# windows form application which allows user to drag-drop file on the form so that the application can get the file path. I just exactly followed what's written on:
How to provide file drag-and-drop functionality in a Visual C# application
It is working on debug mode in Visual Studio environment. However, as soon as I try the same thing on individual exe file which is created on bin/Debug folder, the application does not react to drag-drop.
I have already tried to delete all the files on bin/Debug folder, but the result did not change.
It would be great if somebody has similar issue and solutions for this. Thank you.
Here are the codes I'm trying (after some try and errors it has changed a bit from what's written in the URL shown above, but this still works on Visual Studio but not on exe...) :
private void OpenFile_DragEnter(object sender, DragEventArgs e)
// enable drag-drop event
{
e.Effect = DragDropEffects.Copy;
}
private void OpenFile_DragDrop(object sender, DragEventArgs e)
// open drag-dropped setup file
{
// get drag-dropped file path
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
// open all the files
for (int i = 0; i < s.Length; i++)
{
OpenSetup(s[i]);
}
}
Update: Another thing I found is that I can drag-drop the files on EXE from OpenFileDialog, but not from file exploler.