2

I'm looking for the least painful way (that is, with the least code) to implement DragAcceptFiles on the main window of a C# project.

I've been searching on the net, and it looks like I'll have to DllImport DragAcceptFiles, and override WndProc to catch and handle WM_DROPFILES messages.

Doesn't the .net-framework provide this somewhere? Isn't there a proper way to add message handlers to a form other than overriding WndProc and have it do an extra if on almost all other messages that come through?

Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67
  • possible duplicate of [How do I drag and drop files into a c# application?](http://stackoverflow.com/questions/68598/how-do-i-drag-and-drop-files-into-a-c-application) – Hans Passant Jul 17 '10 at 22:02
  • Ah, one of my upvoted questions that never got accepted as the answer. The memories. – Hans Passant Jul 17 '10 at 22:05

1 Answers1

1

You can enable AllowDrop on the form and handle the DragDrop event. Take a look at the DragEventArgs class for the code for loading a file dropped onto a control.

fletcher
  • 13,380
  • 9
  • 52
  • 69