Obenland
Obenland

Reputation: 866

DragLeave doesn't get called

in my VB.Net application I am try to drag and drop a custom control. It should be dropable onto another instance of the same class. So here is the code I use:

Private Sub HandleMouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseDown
    Me.DoDragDrop(Me, DragDropEffects.Copy)
End Sub

Private Sub HandleDragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles Me.DragEnter
    e.Effect = If(checkDropData(e), DragDropEffects.Copy, DragDropEffects.None)
End Sub

Private Sub HandleDragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles Me.DragDrop
    addControl(e.Data.GetData(GetType(MyControl)))
End Sub

Private Sub HandleDragLeave(ByVal sender As Object, ByVal e As DragEventArgs) Handles Me.DragLeave
    Console.WriteLine("HandleDragLeave: " & sender.ToString)
End Sub

I am able to drop the control but while dragging the DragLeave event never gets called. Did I miss something?

Upvotes: 1

Views: 387

Answers (1)

Obenland
Obenland

Reputation: 866

That's very bad... I used the wrong signature but the was nothing which told me I was wrong.

I found the solution here. I used DragEventArgs instead of EventArgs as type of e. After changing the type it works like expected.

Upvotes: 1

Related Questions