WPF / WinForms中的GiveFeedBack和QueryContinueDrag之间的区别 [英] Difference between GiveFeedBack and QueryContinueDrag in WPF/WinForms

查看:1157
本文介绍了WPF / WinForms中的GiveFeedBack和QueryContinueDrag之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WPF或WinForms中的事件 GiveFeedBack QueryContinueDrag 之间有什么区别?

What is the difference between the events GiveFeedBack and QueryContinueDrag in WPF or WinForms?

我正在阅读的书中指出:

The book I'm reading states:


  • GiveFeedBack:为用户设置一个自定义鼠标指针

  • QueryContinueDrag:启用拖动源来确定是否应该取消拖动事件。

MSDN补充说,在拖动源被拖动的同时,这两个事件都持续被触发

MSDN adds that both events are fired "continuously while the drag source is being dragged"

那么为什么这个分离存在?当然,我也可以在QueryContinueDrag事件中设置一个自定义鼠标指针。

So why does this seperation exist? Surely I could set a custom mouse pointer from within the QueryContinueDrag event as well?

推荐答案

基本上可以设置 e.Effects 属性(从 DragEventArgs 类)到 DragDropEffects.None 从任何暴露它的处理程序中取消拖放操作,例如。 PreviewDrop PreviewDragOver 。因此,在我看来,你是正确的....你不要需要在 QueryContinueDrag 处理程序中执行。

Basically, you can set the e.Effects property (from the DragEventArgs class) to DragDropEffects.None to cancel a drag and drop operation from any handler that exposes it, eg. PreviewDrop, PreviewDragOver. Therefore, in my opinion, you are correct.... you don't need to do it in the QueryContinueDrag handler.

事实上,我有一个完整的拖放系统与图形adorner都通过附加属性实现,我没有打扰实现 QueryContinueDrag 处理程序。

In fact, I have a full working drag and drop system with graphical adorner all achieved through Attached Properties and I haven't bothered to implement the QueryContinueDrag handler at all.

但是,如果要将光标更改为自定义光标,则需要实现 GiveFeedBack 处理程序,因为 GiveFeedbackEventArgs 允许您这样做:

However, if you want to change the cursor to a custom cursor, then you will need to implement a GiveFeedBack handler because the GiveFeedbackEventArgs allows you to do this:

private void PreviewGiveFeedback(object sender, GiveFeedbackEventArgs e)
{
    Mouse.SetCursor(Cursors.No);
    e.Handled = true; // Important! - Hides the normal drag and drop cursors
}

这篇关于WPF / WinForms中的GiveFeedBack和QueryContinueDrag之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆