TheCodeJunkie
TheCodeJunkie

Reputation: 9616

Check if a drag&drop is in progress

Is there any way to check if a drag and drop is in progress? Some method or win32 api which can be checked? I know I can set AllowDrop and use events but it doesn't work in this case. Basically i want to check, with code, if any drag&drop is in progress.

Upvotes: 3

Views: 6799

Answers (4)

Radoslav Hristov
Radoslav Hristov

Reputation: 1053

What about QueryContinueDrag event handler http://msdn.microsoft.com/en-us/library/system.windows.forms.control.querycontinuedrag.aspx ? You can hook a handler to any control and check if there is a ongoing drag&drop operation and then cancel it if you want to.

Ooops, sorry, I just saw that the guy before me already mentioned that. Me bad.

Upvotes: 0

Christopher Edwards
Christopher Edwards

Reputation: 6659

I had a similar question which I answered myself (after some hours messing about) See - How do I tell if a Drag Drop has ended in Winforms?.

Basically if you do as earwicker suggests you need to set the flag when the drag drop begins near the DoDragDrop call. You will need to unset the flag in both the DragDrop event and in the QueryContinueDrag if the QueryContinueDragEventArgs indicate a drop or a cancel.

Upvotes: 2

Daniel Earwicker
Daniel Earwicker

Reputation: 116744

Assuming it's in the context of just your own code, you could identify all the places in your code where a drag/drop happens, and set a global boolean flag to true for the duration of the operation, then back to false after it finishes.

So the next question is, how are drag/drop operations being started in your application?

Upvotes: -1

Thomas
Thomas

Reputation: 182063

The GetCapture API function might be a good start. Basically, when a drag operation starts, the source window "captures" the mouse, which means that it will still receive all mouse events even if the mouse leaves the window.

However, applications can also capture the mouse for other reasons, so this is not 100% reliable. You can try it and see how well it works for you. And with applications doing their own drag&drop handling, there's no way to be sure what is going on anyway.

Upvotes: 0

Related Questions