Valued Contributor
64 Posts
2 Kudos
Registered: ‎11-01-2001
Post 1 of 6

Drag drop item at specific point in AutoCad

442 Views, 5 Replies
06-17-2013 01:14 AM



I would like to use the behaviour of  "drag and drop" into AutoCad (from a listbox in a form) at a specific point, I do not need to drop anything into AutoCad, I just need the exact point of the mouseposition converted to WCS in autocad.


the below code works, but i do not get the correct point in AutoCad.


Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
'---now i drop listbox-text in autocad, 
DoDragDrop(ListBox1.Text, DragDropEffects.Copy)
Dim pt As Point3d = ed.PointToWorld(New Point(CInt(MousePosition.X), CInt(MousePosition.Y)))
'---draw circle
ModelspaceAdd(Teken.Cirkel(pt(0), pt(1), 100))
End Sub



(Maybe it is possible to just change the mouse-cursor, but it doesn't 'lock' the selected item in the listbox, as if it was dragged into the drawing.)


can somebody please help me? 


kind regards,


Wouter de Haan




ADN Support Specialist
352 Posts
27 Kudos
Registered: ‎07-24-2007
Post 2 of 6

Re: Drag drop item at specific point in AutoCad

06-19-2013 08:46 AM in reply to: wbdehaan

Can you give us a sample project to test with please?

Fenton Webb

Developer Technical Services

Autodesk Developer Network

Valued Contributor
64 Posts
2 Kudos
Registered: ‎11-01-2001
Post 3 of 6

Re: Drag drop item at specific point in AutoCad

06-20-2013 07:07 AM in reply to: fenton.webb



the attached project is a simplified version. It now is possible to drag text into the drawing, but the location of the drawn circle is incorrect (maybe because I'm working with two 23" displays), and the text of the listbox is also pasted as mtext in the drawing.


this is what I would like:

Only draw a circle at the exact given point, and no additional listbox text in the drawing.



I have written a macro, in which I can select different items from the listbox into the drawing, Autocad 'knows' at which point the user dropped the item, and i can draw parametric products at the given point, depending on the drawing already created.

Valued Contributor
64 Posts
2 Kudos
Registered: ‎11-01-2001
Post 4 of 6

Re: Drag drop item at specific point in AutoCad

06-20-2013 07:08 AM in reply to: wbdehaan


additional: the Mtext in de upperleft corner, the crosshair where i dropped my item, and the circle drawn at the bottom




*Expert Elite*
1,087 Posts
217 Kudos
Registered: ‎04-27-2009
Post 5 of 6

Re: Drag drop item at specific point in AutoCad

06-20-2013 12:19 PM in reply to: wbdehaan

The reason the circle is drawn far off where you drag and drop is that your code used wrong DODragDrop() method, and also might because you used wrong mouse cursor location.


In your ListBox1_MouseDown() event handler:


DoDragDrop() method is the member of System.Windows.Forms.Control. That is you call this method when you intend to drag somerhing and drop it onto a Windows.Form/Control.


While what you want is to drag and drop into AutoCAD. So, you need to call Autodesk.AutoCAD.ApplicationServices.Application.DoDragDrop(), which has different arguments from Windows.Forms.Control.DoDragDrop. You need to derive a class from Autodesk.AutoCAD.Windows.DropTarget as one of the argument for Application.DoDragDrop.


Since your code is for dropping the dragged data onto the form, not onto AutoCAD, thus the wrong location.


The other reason: you get the mouse cursor location from the form's MousePosition property, which is the cursor's  relative position on the form, not the screen position. But this error is irrelavent, because of calling wrong DoDragDrop() method.


Seeing your question unanswered for 2 days, I wrote on this topic in my blog here:




It may be helpful for what you are doing.

Valued Contributor
64 Posts
2 Kudos
Registered: ‎11-01-2001
Post 6 of 6

Re: Drag drop item at specific point in AutoCad

06-21-2013 07:18 AM in reply to: wbdehaan

Hi Norman Yuan,


thank you for your answer and complete solution. Unfortunately, since i'm rather new to vb.net (converting my macro's from VBA to .Net), when trying to convert your code from C to .net, I keep getting error's. next week I'm going to try again. I'll let you know..have a nice weekend, 


kind regards, Wouter



Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!