dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] Event for Detecting Failed Drag/Drop

  1. #1

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    288

    [RESOLVED] Event for Detecting Failed Drag/Drop

    In my application code is executed during drag/drop which draws pretty cool looking x's across controls that won't accept a drop. Everything works fine if the drag/drop is succesful because i erase the x's in the dragdrop event, but if the user lets go of the left mouse button over a control which doesn't accept a drop then the x's stay on the screen I need an event which is triggered if the drag drop fails. I tried using a simple mouseup event for the entire form but it hasn't worked for some reason.

    Any help would be appreciated. Thanx!
    Last edited by neef; Jan 27th, 2018 at 08:21 PM.
    Intermediate Level Programmer Extraordinaire

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,383

    Re: Event for Detecting Failed Drag/Drop

    I've not done a lot of drag-n-drop so I'm no expert but I'd start by looking at the GiveFeedback and QueryContinueDrag events to see whether they might be of use. That said, can you not just handle DragDrop for those other controls and perform the cleanup without performing the drop?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    288

    Re: Event for Detecting Failed Drag/Drop

    Finally got back to this issue and wanted to report that jmcilhinney's suggested event QueryContinueDrag was the best option for my situation. I also added some code (borrowed from another site) that handled if the user moves the mouse off the form.

    Code:
    Private Sub UCHeadCoachSchedule_QueryContinueDrag(ByVal sender As System.Object, ByVal e As System.Windows.Forms.QueryContinueDragEventArgs) Handles MyBase.QueryContinueDrag  'Other dragdrop controls
    
            Dim lb As CCTrainingLabel = CType(sender, CCTrainingLabel)
            If (lb IsNot Nothing) Then
    
                Dim f As Form = Me.FindForm
    
                ' Cancel the drag if the mouse moves off the form or drops outside a eligible control
                If Control.MousePosition.X < f.DesktopBounds.Left Or Control.MousePosition.X > f.DesktopBounds.Right Or Control.MousePosition.Y < f.DesktopBounds.Top Or Control.MousePosition.Y > f.DesktopBounds.Bottom Or Control.MouseButtons = Windows.Forms.MouseButtons.None Then
                    e.Action = DragAction.Cancel
                    ' Other cleanup code
                 End If
            End if
    End Sub
    Intermediate Level Programmer Extraordinaire

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width