Answered Drag and Drop from container to container...

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
Hi all.

Working on doing a drag drop from one FlowLayoutPanel to another FLP.
these FLPs are in a user control that is added at runtime and there several of them and I populate them with buttons(not that I coudnt use something else) then need to drag them(the buttons) from one FLP on one UC and drop it on a diff UC's FLP.
Hope this isn't to confusing. So since these button are built at runtime I add a Addhandlers for the event they need later - calling them by sender in the SUB ->this sound right so far?

VB.NET:
Private Sub MyMouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Left Then
            dragging = True
        End If
    End Sub
Private Sub MyMouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) 
        If dragging Then
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Me.Cursor = Cursors.Cross
                sender.Location = sender.Location + e.Location
            End If
        End If
    End Sub

I have tried everything I can think of, so here I am. Please correct my thought process if it is all messed up - thanks.
 
Last edited:
Ok getting close...this works, but it only recognizes the edge of the user control as a place to drop the item, not the FLP area???
VB.NET:
Private Sub MyMouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
        DoDragDrop(New myObject(sender), DragDropEffects.Move)
    End Sub
    Private Sub UC_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs)
        If e.Data.GetDataPresent("myObject") Then
            e.Effect = DragDropEffects.All
        End If
    End Sub
    Private Sub UC_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs)
        If e.Data.GetDataPresent("myObject") Then
            Dim u As Unit = CType(sender, Unit)
            Dim btn As Button = CType(e.Data.GetData("myObject"), Button)
            btn.Location = u.FlowLayoutPanel1.PointToClient(New Point(e.X, e.Y))
            u.FlowLayoutPanel1.Controls.Add(btn)
        End If
    End Sub
 Private Class myObject
        Inherits DataObject
        Private Sub New()
        End Sub
        Public Sub New(ByVal btn As Button)
            Me.SetData("myObject", False, btn)
        End Sub
    End Class
 
I got it, I needed to make a DragEnter and DRagDrop for the FLP control as well.
 
Back
Top