Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果拖动或按住鼠标按钮,则发送者不在MouseMove上更新_C#_.net_Vb.net_Parameters_Mousemove - Fatal编程技术网

C# 如果拖动或按住鼠标按钮,则发送者不在MouseMove上更新

C# 如果拖动或按住鼠标按钮,则发送者不在MouseMove上更新,c#,.net,vb.net,parameters,mousemove,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.C

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

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

要覆盖此行为,请将Control.Capure属性设置为False

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

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