如何判断拖放操作是否失败?

时间:2022-08-22 20:26:05

It seems to me there is no way to detect whether a drag operation was successful or not, but there must be some way. Suppose that I want to perform a "move" from the source to the destination. If the user releases the mouse over some app or control that cannot accept the drop, how can I tell?

在我看来,没有办法检测拖动操作是否成功,但必须有一些方法。假设我想从源到目的地执行“移动”。如果用户将鼠标放在某些不能接受掉落的应用程序或控件上,我该怎么说?

For that matter, how can I tell when the drag is completed at all?

就此而言,如何判断拖动何时完成?

I saw this question, but his solution does not work for me, and e.Action is always Continue.

我看到了这个问题,但他的解决方案对我不起作用,e.Action总是继续。

3 个解决方案

#1


7  

I'm not sure if that can help you, but DoDragDrop method returns final DragDropEffects value.

我不确定这是否可以帮到你,但DoDragDrop方法返回最终的DragDropEffects值。

var ret = DoDragDrop( ... );
if(ret == DragDropEffects.None) //not successfull
else // etc.

#2


3  

Ah, I think I've got it. Turns out the call to DoDragDrop is actually synchronous (how lame), and returns a value of DragDropEffects, which is set to None if the op fails. So basically this means the app (or at least the UI thread) will be frozen for so long as the user is in the middle of a drag. That does not seem a very elegant solution to me.

啊,我想我已经明白了。原来对DoDragDrop的调用实际上是同步的(多么蹩脚),并返回DragDropEffects的值,如果op失败则设置为None。所以基本上这意味着只要用户处于拖动的中间,app(或至少是UI线程)就会被冻结。这对我来说似乎不是一个非常优雅的解决方案。

Ok cz_dl I see you just posted that very thing so I'll give u the answer.

好的cz_dl我看到你刚发布了那个东西所以我会给你答案。

This I don't understand though: how can the destination determine whether the op should be a move or a copy? Shouldn't that be up to the source app?

我不明白这一点:目的地如何确定op应该是移动还是副本?不应该是源应用程序?

#3


0  

Can't add comment yet, so another answer. I was also surprised when I saw for the first time, that DoDragDrop is called synchronously and it somehow doesn't froze the UI.

无法添加评论,所以另一个答案。当我第一次看到DoDragDrop被同步调用时,我也感到惊讶,它不知何故没有冻结UI。

But the copy/move stuff I believe is perfectly logical. You can specify allowed effects while calling DoDragDrop method in source app and that's all what's important to you. How destination app will handle and use the data it's up to it.

但我相信复制/移动的东西是完全合乎逻辑的。您可以在源应用程序中调用DoDragDrop方法时指定允许的效果,这对您来说非常重要。目标应用程序将如何处理和使用它所依赖的数据。

#1


7  

I'm not sure if that can help you, but DoDragDrop method returns final DragDropEffects value.

我不确定这是否可以帮到你,但DoDragDrop方法返回最终的DragDropEffects值。

var ret = DoDragDrop( ... );
if(ret == DragDropEffects.None) //not successfull
else // etc.

#2


3  

Ah, I think I've got it. Turns out the call to DoDragDrop is actually synchronous (how lame), and returns a value of DragDropEffects, which is set to None if the op fails. So basically this means the app (or at least the UI thread) will be frozen for so long as the user is in the middle of a drag. That does not seem a very elegant solution to me.

啊,我想我已经明白了。原来对DoDragDrop的调用实际上是同步的(多么蹩脚),并返回DragDropEffects的值,如果op失败则设置为None。所以基本上这意味着只要用户处于拖动的中间,app(或至少是UI线程)就会被冻结。这对我来说似乎不是一个非常优雅的解决方案。

Ok cz_dl I see you just posted that very thing so I'll give u the answer.

好的cz_dl我看到你刚发布了那个东西所以我会给你答案。

This I don't understand though: how can the destination determine whether the op should be a move or a copy? Shouldn't that be up to the source app?

我不明白这一点:目的地如何确定op应该是移动还是副本?不应该是源应用程序?

#3


0  

Can't add comment yet, so another answer. I was also surprised when I saw for the first time, that DoDragDrop is called synchronously and it somehow doesn't froze the UI.

无法添加评论,所以另一个答案。当我第一次看到DoDragDrop被同步调用时,我也感到惊讶,它不知何故没有冻结UI。

But the copy/move stuff I believe is perfectly logical. You can specify allowed effects while calling DoDragDrop method in source app and that's all what's important to you. How destination app will handle and use the data it's up to it.

但我相信复制/移动的东西是完全合乎逻辑的。您可以在源应用程序中调用DoDragDrop方法时指定允许的效果,这对您来说非常重要。目标应用程序将如何处理和使用它所依赖的数据。