It is clear that this is old, but I came across this message, looking at the same thing. I thought that there could be a real drag event, but I think not. Here is how I did it.
Private Sub ContainerToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ContainerToolStripMenuItem.Click Dim pnl As New Panel pnl.Size = New Size(160, 160) pnl.BackColor = Color.White AddHandler pnl.MouseDown, AddressOf Control_DragEnter AddHandler pnl.MouseUp, AddressOf Control_DragLeave AddHandler pnl.MouseMove, AddressOf Control_Move Me.Controls.Add(pnl) End Sub Private Sub Control_DragEnter(ByVal sender As Object, ByVal e As EventArgs) MouseDragging = True End Sub Private Sub Control_DragLeave(ByVal sender As Object, ByVal e As EventArgs) MouseDragging = False End Sub Private Sub Control_Move(ByVal sender As Object, ByVal e As EventArgs) If MouseDragging = True Then sender.Location = Me.PointToClient(Control.MousePosition) End If End Sub
ContainerToolStripMenuItem from my ToolStrip, which adds a panel on the fly. MouseDragging - class level. Dragged like a charm. Also, do not use Cursor.Position , as it will return the position relative to your entire window, and not the form (or any other container you are in).
source share