如果拖动或鼠标按钮保持,发件人不会在MouseMove上更新

时间:2011-09-10 04:06:37

标签: c# .net vb.net parameters mousemove

我正在尝试实施自定义拖动操作来对面板进行排序。

我将一个对象分配给MouseDown事件中的变量,并通过检查相邻面板的MouseMove事件来跟踪它的相对位置,因为我将鼠标拖到它们上面。

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

问题是MouseMove事件的Sender参数永远不会改变 - 它总是返回接收MouseDown事件的对象。

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

为什么MouseMove的Sender参数没有返回鼠标当前结束的实际对象?

1 个答案:

答案 0 :(得分:0)

要覆盖此行为,请将Control.Capure属性设置为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

现在MouseMove事件返回鼠标移动的实际对象!