#730 – 使用QueryContinueDrag 事件(Use QueryContinueDrag Event to Know When Mouse Button State Changes)
来源:互联网 发布:任意号码显示软件 编辑:程序博客网 时间:2024/05/17 21:49
原文地址:https://wpf.2000things.com/2013/01/09/730-use-querycontinuedrag-event-to-know-when-mouse-button-state-changes/
当在拖拽的操作过程中,鼠标或者键盘的按键状态(Ctrl, Shift 或者Alt)发生改变,QueryContinueDrag 事件就会被触发。
下面的例子中,当拖拽的过程中鼠标左键被放开时,改变源控件中的内容。
<Label Content="Drag from here" Background="LavenderBlush" HorizontalAlignment="Center" Margin="10" Padding="10" MouseDown="Label1_MouseDown" QueryContinueDrag="Label1_QueryContinueDrag"/><Label Content="To here" Background="SandyBrown" AllowDrop="True" HorizontalAlignment="Center" Margin="10" Padding="10" Drop="Label2_Drop"/>上面两个Label,第一个作为拖动的源,第二个是接收拖动的控件。下面是CS代码。
private void Label1_MouseDown(object sender, MouseButtonEventArgs e){ Label lblFrom = e.Source as Label; if (e.LeftButton == MouseButtonState.Pressed) DragDrop.DoDragDrop(lblFrom, lblFrom.Content, DragDropEffects.Copy);} private void Label1_QueryContinueDrag(object sender, QueryContinueDragEventArgs e){ Label lblFrom = e.Source as Label; if (!e.KeyStates.HasFlag(DragDropKeyStates.LeftMouseButton)) lblFrom.Content = "...";} private void Label2_Drop(object sender, DragEventArgs e){ string draggedText = (string)e.Data.GetData(DataFormats.StringFormat); Label toLabel = e.Source as Label; toLabel.Content = draggedText;}
阅读全文
0 0
- #730 – 使用QueryContinueDrag 事件(Use QueryContinueDrag Event to Know When Mouse Button State Changes)
- How to Use the Mouse Wheel Event in HTML5 Pages
- Effective Objective-C 2.0: Item 43: Know When to Use GCD and When to Use Operation Queues
- use "OnCommand" event to handle multiple button click
- Use Your Wisdom to Know When It's Time to Let Go
- 干活来袭:Effective Concurrency: Know When to Use an Active Object Instead of a Mutex
- Define a one-to-many dependency between objects so that when one object changes state, all its depe
- When to use DMU?
- When to use AtomicReference?
- How to simulate Mouse Click event
- 什么时候使用Decimal 类型(When to Use the Decimal Type)
- Good testers know when to quit
- When to use assert() and when to use try catch?
- When to use Class.isInstance() & when to use instanceof operator
- when to use Java Beans
- msdn:when to use udp
- When to use virtual destructor?
- Get - When you don't know phrasal verbs, use "GET"
- 压栈思想计算Java运算表达式
- Delphi常用系统函数总结
- 【代码笔记】iOS-产生随机字符串
- ftp与sftp文件上传工具类
- QT5学习
- #730 – 使用QueryContinueDrag 事件(Use QueryContinueDrag Event to Know When Mouse Button State Changes)
- SQL入门经典思维导图学习
- Android Webview不能占满整个activity解决办法
- js 冰河世纪
- 新浪是如何分析处理32亿条实时日志的?
- 对JavaEE中mvc模式以及三层架构的理解
- LearningNotes
- 测线程cpu时间
- 超级简单的Android Studio jni 实现(无需命令行)