简体   繁体   English

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

[英]How can I tell if a drag and drop operation failed?

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 总是 Continue

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.

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. 原来对DoDragDrop的调用实际上是同步的 (多么蹩脚),并返回DragDropEffects的值,如果op失败则设置为None 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. 所以基本上这意味着只要用户处于拖动的中间,app(或至少是UI线程)就会被冻结。 That does not seem a very elegant solution to me. 这对我来说似乎不是一个非常优雅的解决方案。

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? 我不明白这一点:目的地如何确定op应该是移动还是副本? Shouldn't that be up to the source app? 这不应该取决于源应用程序吗?

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. 您可以在源应用程序中调用DoDragDrop方法时指定允许的效果,这对您来说非常重要。 How destination app will handle and use the data it's up to it. 目标应用程序将如何处理和使用它所依赖的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM