Drag & Drop file from external application

By Adam Nagy

You may want to provide a user control with a list of components that you could drag & drop onto Inventor. In case of .NET it's quite easy to set up. You just have to handle the MouseDown event of the control from which you want to enable the Drag & Drop, and then set up the data that could be dragged onto another applications.

In this case we have a simple .NET Form with a button on it named myButton with text "Drag Me!". If the user starts dragging this button then it will drag a file onto other applications like Inventor, which accept such a thing.

Here is the main part of the C# source code:

using System; using System.Collections.Specialized; using System.Windows.Forms;  namespace DragAndDropTest {   public partial class MyForm : Form   {     public MyForm()     {       InitializeComponent();     }      private void myButton_MouseDown(      object sender, MouseEventArgs e)     {       DataObject dragInfo = new DataObject();       StringCollection coll = new StringCollection();       coll.Add(@"c:temptest.ipt");       dragInfo.SetFileDropList(coll);        // "Copy" will let us open the ipt       // "Link" will let us insert the ipt in an assembly       myButton.DoDragDrop(         dragInfo,         DragDropEffects.Copy | DragDropEffects.Link);     }   } }

Here it is in action:

Drag&Drop

 


Comments

3 responses to “Drag & Drop file from external application”

  1. can you create a addin for this please?

  2. Hi Maxim,
    Addin source code can be downloaded from below link.
    https://myshare.autodesk.com/:f:/g/personal/chandra_shekar_g_autodesk_com/Ev1N4_N2H01Hrt3WbX15d9kB56qw-r9fAk757RcMwjGBBg?e=eqtluh
    Thanks and regards,
    Chandra shekar G

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading