Link to home
Start Free TrialLog in
Avatar of const71
const71

asked on

HOW CAN A USER CANCEL A DRAG AND DROP OPERATION IN VISUAL BASIC?

I have set my control for manual drag and drop,

in the mouse move event, i check to see if the left mouse button is down and immediately call Drag method to initiate a drag and drop operation.

While the user is dragging the control, how do i code it so that if the user clicks the escape key (or perhaps the right mouse button), the drag and drop is cancelled completely (ie no further DragOver or DragDrop event will be called until I once again initiate the whole sequence over with another call to Drag

During drag and drop all mouse events seem to be turned off untill the end of the drag and drop operation so i am not even sure if i can cancel the drag and drop with a right mouse click. --If it is too difficult, I will settle for the escape key :)

Hope this makes sense
ASKER CERTIFIED SOLUTION
Avatar of Brownhead
Brownhead

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of const71
const71

ASKER

That seems to work for the mouse button but not for escape key. Also, what if the right mouse is never clicked and the user always performs drag and drop without ever pressing right mouse?  will this  loop forever?
Avatar of const71

ASKER

yep,

i put a beep in the loop and my program can't finish until it has exhausted all beeps yet to be played.
Isnt there a cleaner way to do this?
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of const71

ASKER

Great code guys!

The use of timer is probably not the way to go in my opinion as the user will only realize their drag was canceled when the Timer interval is reached. Shorten that interval too much and you're wasting cycles.

But the code did give me some ideas about keyboard manipulation which I need.  I guess first approach with some tweaks will work best.


Thanks guys