<p>I've seen this done in Borland's <a href="https://en.wikipedia.org/wiki/Turbo_C++" rel="noreferrer">Turbo C++</a> environment, but I'm not sure how to go about it for a C# application I'm working on. Are there best practices or gotchas to look out for?</p>

[{'answer_id': 68722, 'author': 'Judah Gabriel Himango', 'author_id': 536, 'author_profile': 'https://Stackoverflow.com/users/536', 'pm_score': 6, 'selected': False, 'text': "<p>In Windows Forms, set the control's AllowDrop property, then listen for DragEnter event and DragDrop event.</p>\n\n<p>When the <code>DragEnter</code> event fires, set the argument's <code>AllowedEffect</code> to something other than none (e.g. <code>e.Effect = DragDropEffects.Move</code>).</p>\n\n<p>When the <code>DragDrop</code> event fires, you'll get a list of strings. Each string is the full path to the file being dropped.</p>\n"}, {'answer_id': 68808, 'author': 'Phil Wright', 'author_id': 6276, 'author_profile': 'https://Stackoverflow.com/users/6276', 'pm_score': 4, 'selected': False, 'text': '<p>You need to be aware of a gotcha. Any class that you pass around as the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.dataobject%28v=vs.110%29.aspx" rel="noreferrer">DataObject</a> in the drag/drop operation has to be Serializable. So if you try and pass an object, and it is not working, ensure it can be serialized as that is almost certainly the problem. This has caught me out a couple of times!</p>\n'}, {'answer_id': 68922, 'author': 'Craig Eddy', 'author_id': 5557, 'author_profile': 'https://Stackoverflow.com/users/5557', 'pm_score': 3, 'selected': False, 'text': "<p>Another common gotcha is thinking you can ignore the Form DragOver (or DragEnter) events. I typically use the Form's DragOver event to set the AllowedEffect, and then a specific control's DragDrop event to handle the dropped data.</p>\n"}, {'answer_id': 89470, 'author': 'Hans Passant', 'author_id': 17034, 'author_profile': 'https://Stackoverflow.com/users/17034', 'pm_score': 9, 'selected': False, 'text': '<p>Some sample code:</p>\n\n<pre><code>  public partial class Form1 : Form {\n    public Form1() {\n      InitializeComponent();\n      this.AllowDrop = true;\n      this.DragEnter += new DragEventHandler(Form1_DragEnter);\n      this.DragDrop += new DragEventHandler(Form1_DragDrop);\n    }\n\n    void Form1_DragEnter(object sender, DragEventArgs e) {\n      if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;\n    }\n\n    void Form1_DragDrop(object sender, DragEventArgs e) {\n      string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);\n      foreach (string file in files) Console.WriteLine(file);\n    }\n  }\n</code></pre>\n'}, {'answer_id': 300182, 'author': 'Guge', 'author_id': 37771, 'author_profile': 'https://Stackoverflow.com/users/37771', 'pm_score': 4, 'selected': False, 'text': "<p>Yet another gotcha:</p>\n\n<p>The framework code that calls the Drag-events swallow all exceptions. You might think your event code is running smoothly, while it is gushing exceptions all over the place. You can't see them because the framework steals them.</p>\n\n<p>That's why I always put a try/catch in these event handlers, just so I know if they throw any exceptions. I usually put a Debugger.Break(); in the catch part.</p>\n\n<p>Before release, after testing, if everything seems to behave, I remove or replace these with real exception handling.</p>\n"}, {'answer_id': 4789883, 'author': 'Wayne Uroda', 'author_id': 588476, 'author_profile': 'https://Stackoverflow.com/users/588476', 'pm_score': 7, 'selected': False, 'text': '<p>Be aware of windows vista/windows 7 security rights - if you are running Visual Studio as administrator, you will not be able to drag files from a non-administrator explorer window into your program when you run it from within visual studio. The drag related events will not even fire! I hope this helps somebody else out there not waste hours of their life...</p>\n'}, {'answer_id': 36721291, 'author': 'CAD bloke', 'author_id': 492, 'author_profile': 'https://Stackoverflow.com/users/492', 'pm_score': 3, 'selected': False, 'text': '<p>Here is something I used  to drop files and/or folders full of files. In my case I was filtering for <code>*.dwg</code> files only and chose to include all subfolders.</p>\n\n<p><code>fileList</code> is an <code>IEnumerable</code> or similar In my case was bound to a WPF control... </p>\n\n<pre class="lang-cs prettyprint-override"><code>var fileList = (IList)FileList.ItemsSource;\n</code></pre>\n\n<p>See <a href="https://stackoverflow.com/a/19954958/492">https://stackoverflow.com/a/19954958/492</a> for details of that trick.</p>\n\n<p>The drop Handler ...</p>\n\n<pre class="lang-cs prettyprint-override"><code>  private void FileList_OnDrop(object sender, DragEventArgs e)\n  {\n    var dropped = ((string[])e.Data.GetData(DataFormats.FileDrop));\n    var files = dropped.ToList();\n\n    if (!files.Any())\n      return;\n\n    foreach (string drop in dropped)\n      if (Directory.Exists(drop))\n        files.AddRange(Directory.GetFiles(drop, "*.dwg", SearchOption.AllDirectories));\n\n    foreach (string file in files)\n    {\n      if (!fileList.Contains(file) &amp;&amp; file.ToLower().EndsWith(".dwg"))\n        fileList.Add(file);\n    }\n  }\n</code></pre>\n'}, {'answer_id': 48620095, 'author': 'Roland', 'author_id': 1845672, 'author_profile': 'https://Stackoverflow.com/users/1845672', 'pm_score': 2, 'selected': False, 'text': '<p>The solution of Judah Himango and Hans Passant is available in the Designer (I am currently using VS2015):</p>\n\n<p><a href="https://i.stack.imgur.com/chX8I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/chX8I.png" alt="enter image description here"></a></p>\n\n<p><a href="https://i.stack.imgur.com/2R8Wx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2R8Wx.png" alt="enter image description here"></a></p>\n'}, {'answer_id': 61456003, 'author': 'Ernest Rutherford', 'author_id': 11660685, 'author_profile': 'https://Stackoverflow.com/users/11660685', 'pm_score': 0, 'selected': False, 'text': '<p>You can implement Drag&amp;Drop in WinForms and WPF. </p>\n\n<ul>\n<li>WinForm (Drag from app window)</li>\n</ul>\n\n<p>You should add mousemove event:</p>\n\n<pre><code>private void YourElementControl_MouseMove(object sender, MouseEventArgs e)\n\n    {\n     ...\n         if (e.Button == MouseButtons.Left)\n         {\n                 DoDragDrop(new DataObject(DataFormats.FileDrop, new string[] { PathToFirstFile,PathToTheNextOne }), DragDropEffects.Move);\n         }\n     ...\n    }\n</code></pre>\n\n<ul>\n<li>WinForm (Drag to app window)</li>\n</ul>\n\n<p>You should add DragDrop event:</p>\n\n<p>private void YourElementControl_DragDrop(object sender, DragEventArgs e)</p>\n\n<pre><code>    {\n       ...\n       foreach (string path in (string[])e.Data.GetData(DataFormats.FileDrop))\n            {\n                File.Copy(path, DirPath + Path.GetFileName(path));\n            }\n       ...\n    }\n</code></pre>\n\n<p><a href="https://www.brainbeast.best/drag-and-drop-on-c-sharp-in-wpf-dot-net/" rel="nofollow noreferrer">Source with full code</a>.</p>\n'}, {'answer_id': 62944471, 'author': 'Jack', 'author_id': 3646777, 'author_profile': 'https://Stackoverflow.com/users/3646777', 'pm_score': 0, 'selected': False, 'text': '<p>Note that for this to work, you also need to set the dragDropEffect within _drawEnter...</p>\n<pre><code>private void Form1_DragEnter(object sender, DragEventArgs e)\n{\n    Console.WriteLine(&quot;DragEnter!&quot;);\n    e.Effect = DragDropEffects.Copy;\n}\n</code></pre>\n<p>Source: <a href="https://stackoverflow.com/questions/26628492/drag-and-drop-not-working-in-c-sharp-winforms-application">Drag and Drop not working in C# Winforms Application</a></p>\n'}]
['https://Stackoverflow.com/questions/68598', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']