【问题标题】:Sender not updating on MouseMove if dragging or mouse button held如果拖动或按住鼠标按钮,发件人不会在 MouseMove 上更新
【发布时间】:2011-09-10 04:06:36
【问题描述】:

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

我在 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 参数没有返回鼠标当前所在的实际对象?

【问题讨论】:

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


    【解决方案1】:

    要覆盖此行为,请将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 事件返回鼠标移动的实际对象!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多