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 引数が、現在マウスが置かれている実際のオブジェクトを返さないのはなぜですか?

4

1 に答える 1

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 イベントは、マウスが移動した実際のオブジェクトを返します!

于 2011-09-10T04:07:03.307 に答える