Sender not updating on MouseMove if dragging or mouse button held
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.Capure
property to False
.
Private Sub ThumbnailMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
DirectCast(sender, Windows.Forms.Control).Capture = False 'Don't capture the mouse
_thumbnailMove = DirectCast(sender, Windows.Forms.Control)
End Sub
And now the MouseMove event returns the actual object that the mouse moves over!
精彩评论