2011-09-10 1 views
0

패널을 정렬하기 위해 사용자 지정 끌기 작업을 구현하려고합니다.끌기 또는 마우스 단추를 누른 경우 보낸 사람이 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 인수가 마우스가 현재 가지고있는 실제 개체를 반환하지 않는 이유는 무엇입니까?

답변

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 이벤트는 마우스가 움직이는 실제 개체를 반환합니다!

관련 문제