[英]Sender not updating on MouseMove if dragging or mouse button held
我正在嘗試實現自定義拖動操作以對面板進行排序。
我將對象分配給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
。
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事件將返回鼠標移過的實際對象!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.