This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Drag and Drop positioning

I've been struggling with this for some time, I know it's probably simple, but I need some help. I have a Form in VB.NET where I need to enable a user to create an Ellipse on a canvas by drag and drop. I have a PictureBox on the Form that a user can drag and drop onto a layer of of the MultiLayerViewer, but on the DragDrop event, I can never seem to create an Elliple at the location the user dropped.

Any help or pointing in the right direction would greatly be appreciated.

My code is as follows:

    Private Sub _multiLayerViewer_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles _multiLayerViewer.DragDrop

        Dim a As Aurigma.GraphicsMill.WinControls.VObject
        Dim Pt As Point

        Pt = Me.PointToClient(New Point(e.X, e.Y))
        Pt.Offset(-DragPoint.X, -DragPoint.Y)  ' DragPoint is being set when user begins drag

        a = New Aurigma.GraphicsMill.WinControls.EllipseVObject(Pt.X, Pt.Y, 10, 10)
        _multiLayerViewer.CurrentLayer.VObjects.Add(a)


    End Sub
I first used the PointToClient method to convert the cursor position to a point within the MultiLayerViewer control and then used the ControlToWorkspace method to convert it to a point within the workspace.

Example (documentPage is of type MultiLayerViewer)

        private void documentPage_DragDrop(object sender, DragEventArgs e)
        {
            thumbNail1.Visible = false;

            //convert cursor location to point within control
            Point controlLocation = documentPage.PointToClient(new Point(e.X, e.Y));

            //convert control location to point within workspace
            PointF workspaceLocation = documentPage.ControlToWorkspace(controlLocation, Aurigma.GraphicsMill.Unit.Point);

            //create new image object at workspace location
            Aurigma.GraphicsMill.WinControls.ImageVObject newImageVObject = new
                Aurigma.GraphicsMill.WinControls.ImageVObject(getBitMap(lastFilename), false, workspaceLocation.X, workspaceLocation.Y);

            //Add the image to layer
            documentPage.Layers[0].VObjects.Add(newImageVObject);
        }
Hello bcardi,

Thank you for your answer! 🙂
Hello bcardi,

Thanks for your post... for some reason (maybe it was the level I was Zoomed in at on my Control) the code wouldn't place an object at that location, but your post got me going in the right direction. Thanks!

hopefully this might help others out, but here is what works for me in my DragDrop event:

Dim Pt As Point
Pt = Me.MultiLayerViewer1.PointToClient(New Point(e.X, e.Y))

Dim aPoint As PointF
aPoint = Me.MultiLayerViewer1.ControlToWorkspace(New Point(Pt.X, Pt.Y), Aurigma.GraphicsMill.Unit.Point)
' I can now place an object at aPoint like such:
Dim a As Aurigma.GraphicsMill.WinControls.VObject
a = New Aurigma.GraphicsMill.WinControls.EllipseVObject(aPoint.X - 5, aPoint.Y - 5, 10, 10)


Thanks again!
Dustin