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

发布于 2024-12-03 18:31:34 字数 676 浏览 2 评论 0原文

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

我将一个对象分配给 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 参数不返回鼠标当前悬停的实际对象?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是一片海 2024-12-10 18:31:34

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

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文