code_junkie

How do I tell if a Drag Drop has ended in Winforms

Nov 13th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. Private Sub MyControl_QueryContinueDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.QueryContinueDragEventArgs) Handles MyControl.QueryContinueDrag
  2.  
  3. Dim MousePointerLocation As Point = MousePosition
  4.  
  5. If e.Action = DragAction.Cancel Then '' User pressed the Escape button
  6. DragDropInProgressFlag = False
  7. End If
  8.  
  9. If e.Action = DragAction.Drop Then
  10. If Not HitTest(new {MyControl1, MyControl2}, MousePointerLocation) Then
  11. DragDropInProgressFlag = False
  12. End If
  13. End If
  14.  
  15. End Sub
  16.  
  17. Private Function HitTest(ByVal ctls() As Control, ByVal p As Point) As Boolean
  18.  
  19. HitTest = False
  20.  
  21. For Each ctl In ctls
  22. Dim ClientPoint As Point = ctl.PointToClient(p)
  23. HitTest = HitTest Or (ClientPoint.X >= 0 AndAlso ClientPoint.Y >= 0 AndAlso ClientPoint.X <= ctl.Width AndAlso ClientPoint.Y <= ctl.Height)
  24. If HitTest Then Exit For
  25. Next
  26.  
  27. End Function
Add Comment
Please, Sign In to add comment