Basic drag and drop in WinForms
来源:互联网 发布:软件测试流程规范化 编辑:程序博客网 时间:2024/05/21 22:56
http://codebetter.com/petervanooijen/2007/07/07/basic-drag-and-drop-in-winforms/
1.Start the drag operation in the originator. This is done by invoking the DoDragDrop method, a member of the Control base class. The average user expects to start a drag by clicking the mouse button, so agood place to fire of the method is the MouseDown event.The DoDragDrop method takes two parameters, the first one is an object which can contain any data you wish to drop on the target. The second parameter is an enumeration providing some info on the intent of the originator.
private void label_MyMouseDown(object sender, MouseEventArgs e){ DoDragDrop((sender as Label).Text, DragDropEffects.Link);}
2. Selectpotential drop targets by setting their AllowDrop property to true.
3. In the drop target determine whether it will accept a drop. This is done in the DragEnter event. The code can inspect the originator’s intent by examining the AllowedEffect property. This enumeration has a bitflag, so it can combine several AllowedEffect‘s. The code can also check if data of a certain desired type is available by inspecting the Data property. Here the listbox checks on the Link effect and checks for the presence of string data.
private void listBox_MyDragEnter(object sender, DragEventArgs e){ if ((e.AllowedEffect & DragDropEffects.Link) != 0 && e.Data.GetDataPresent(typeof(string))) e.Effect = DragDropEffects.Link;}
By setting the Effect property the target tells it will accept a drop. The value of the Effect property determines what the cursor looks like when it enters the target.Targets which don’t have the AllowDrop property set or refuse to accept a drop will display a “no access” cursor.
4. Accept the drop and handle the data. When the user release the mouse and the target has expressed it will accept a drop the DragDrop event fires.
private void listBox_MyDragDrop(object sender, DragEventArgs e){ (sender as ListBox).Items.Add(e.Data.GetData(typeof (string))); }
- Basic drag and drop in WinForms
- Drag And Drop In Javascript
- Drag and Drop in WPF
- Drag and drop in unity
- Simple Drag and Drop in ExtJS
- Drag and Drop
- 学习drag and drop
- 关于drag and drop
- html5 Drag and drop
- Ajax Drag and Drop
- QT5 drag and drop
- HTML5 Drag and Drop
- drag and drop学习
- android - Drag and Drop
- html5 Drag and Drop
- Qt Drag and Drop
- drag and drop(拖拽)
- Drag And Drop 进阶
- windows 下保存shell文件为可以在Linux下运行的格式
- javascript验证身份证完全方法.
- From LOW to PWNED [3] JBoss/Tomcat server-status
- Xcode 4.3 Three20 安装 320
- Flex创建AIR项目
- Basic drag and drop in WinForms
- 后缀数组
- Q_SIGNALS,Q_SLOTS, Q_EMIT
- 你不明白的压力—选择创业,就是选择生死
- 每一个孩子都是天才,每一个天才都与众不同——《地球上的星星》观后感
- MySQL锁表研究
- android2.3 Luncher2开启3D效果(图标、字体模糊解决方法)
- Bypassing HTTP Basic Authentication in PHP Applications
- Oracle RBA(Redo Byte Address) 说明