I am trying to implemented a custom dragging operation to sort panels.
I assign an object to a variable in the MouseDown event and track it’s relative position by examining the MouseMove event of the neighbouring panels as I drag the mouse over them.
Private Sub ThumbnailMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
_thumbnailMove = DirectCast(sender, Windows.Forms.Control) ‘The object to move
End Sub
The problem is that the Sender parameter of the MouseMove event never changes – it always returns the object that received the MouseDown event.
Private Sub ThumbnailMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Console.WriteLine(sender.Name) 'Always returns the name of the _thumbnailToMove
End Sub
Why is the Sender argument of MouseMove not returning the actual object that the mouse is currently over?
To override this behaviour, set the
Control.Capureproperty toFalse.And now the MouseMove event returns the actual object that the mouse moves over!