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.
有没有办法检查拖放是否正在进行中?有些方法或win32 api可以检查吗?我知道我可以设置AllowDrop并使用事件,但在这种情况下它不起作用。基本上我想用代码检查是否有任何拖放正在进行中。
4 个解决方案
#1
2
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?.
我有一个类似的问题,我自己回答(几个小时后搞乱)请参阅 - 如何判断Drag Drop是否已在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.
基本上,如果你做耳标建议你需要在DoDragDrop调用附近开始拖拽时设置标志。如果QueryContinueDragEventArgs指示丢弃或取消,则需要在DragDrop事件和QueryContinueDrag中取消设置标志。
#2
0
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.
GetCapture API函数可能是一个好的开始。基本上,当拖动操作开始时,源窗口“捕获”鼠标,这意味着即使鼠标离开窗口它仍将接收所有鼠标事件。
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.
但是,应用程序也可以出于其他原因捕获鼠标,因此这不是100%可靠。你可以尝试一下,看看它对你有多好。应用程序执行自己的拖放处理时,无论如何都无法确定发生了什么。
#3
0
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.
那么QueryContinueDrag事件处理程序http://msdn.microsoft.com/en-us/library/system.windows.forms.control.querycontinuedrag.aspx呢?您可以将处理程序挂钩到任何控件并检查是否存在正在进行的拖放操作,然后根据需要取消它。
Ooops, sorry, I just saw that the guy before me already mentioned that. Me bad.
哎呀,对不起,我刚才看到我之前的那个人已经提到过了。我不好
#4
-1
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.
假设它只在您自己的代码的上下文中,您可以识别代码中发生拖放的所有位置,并在操作持续时间内将全局布尔标志设置为true,然后在完成后返回false。
So the next question is, how are drag/drop operations being started in your application?
接下来的问题是,如何在应用程序中启动拖放操作?
#1
2
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?.
我有一个类似的问题,我自己回答(几个小时后搞乱)请参阅 - 如何判断Drag Drop是否已在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.
基本上,如果你做耳标建议你需要在DoDragDrop调用附近开始拖拽时设置标志。如果QueryContinueDragEventArgs指示丢弃或取消,则需要在DragDrop事件和QueryContinueDrag中取消设置标志。
#2
0
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.
GetCapture API函数可能是一个好的开始。基本上,当拖动操作开始时,源窗口“捕获”鼠标,这意味着即使鼠标离开窗口它仍将接收所有鼠标事件。
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.
但是,应用程序也可以出于其他原因捕获鼠标,因此这不是100%可靠。你可以尝试一下,看看它对你有多好。应用程序执行自己的拖放处理时,无论如何都无法确定发生了什么。
#3
0
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.
那么QueryContinueDrag事件处理程序http://msdn.microsoft.com/en-us/library/system.windows.forms.control.querycontinuedrag.aspx呢?您可以将处理程序挂钩到任何控件并检查是否存在正在进行的拖放操作,然后根据需要取消它。
Ooops, sorry, I just saw that the guy before me already mentioned that. Me bad.
哎呀,对不起,我刚才看到我之前的那个人已经提到过了。我不好
#4
-1
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.
假设它只在您自己的代码的上下文中,您可以识别代码中发生拖放的所有位置,并在操作持续时间内将全局布尔标志设置为true,然后在完成后返回false。
So the next question is, how are drag/drop operations being started in your application?
接下来的问题是,如何在应用程序中启动拖放操作?