For example, I want to drop a file "C:\test.txt" into Notepad. I used the following code. (An existing answer used DragDrop.DoDragDrop
instead, but that seemed to belong to WPF.)
private void label1_MouseDown(object sender, MouseEventArgs e)
{
var file = new DataObject(DataFormats.FileDrop, new string[] { @"C:\test.txt" });
label1.DoDragDrop(file, DragDropEffects.Copy | DragDropEffects.Move);
}
"Notepad" did not seem to get the file drop. It did show the [+] cursor, but when I dropped it, nothing happened. I tried with "Notepad++"; it did not work either. It worked with "WordPad" and "HxD", however. What is wrong with the code above?
It seems that x86/x64 is the issue. Notepad and Notepad++ on my system are 64-bit versions. My app was compiled for x86 by the default setting. When I compiled my app for x64, dragging file to Notepad worked.