Drag and Drop text containing file in textbox.
来源:互联网 发布:mac系统免费软件 编辑:程序博客网 时间:2024/05/01 04:40
In many of application we need drag and drop functionality; in that same context this article helps you to drag and drop text containing file in to text box. This is a simplest method which I found for text file drag and drop. In case of drag and drop Microsoft .NET has provided support by may properties to control, events and methods. In this application you can drag and drop a file which may of any extension but contains text in it. For text container I used This property is set to This event is fired whenever the mouse with a pressed left button will enter into a control's region. At that time, the control's DragDrop This event is fired when the left mouse button is released by the user and the user intends to drop data on the target control. Generally, the target control accepts data here as follows. This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below. A list of licenses authors might use can be found hereIntroduction
textbox.
For performing drag and drop I handled DragEnter
, DragDrop
event of TextBox and the AllowDrop
property.Property
AllowDrop
true
for any control for which we want drag and drop support. This control may be a TextBox
which holds data.Events
DragEnter
DragEnter
event is fired. Generally, we require to check the type of data available, which is done as follows.private void txtFileContent_DragEnter(object sender, DragEventArgs e){ // If file is dragged, show cursor "Drop allowed" if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None;}
private void txtFileContent_DragDrop(object sender, DragEventArgs e){ try { Array a = (Array) e.Data.GetData(DataFormats.FileDrop); if(a != null) { string s = a.GetValue(0).ToString(); this.Activate(); OpenFile(s); } } catch(Exception ex) { MessageBox.Show("Error in DragDrop function: " + ex.Message); }}
License
About the Author
Shinde Sachin
Patni, India
India
- Drag and Drop text containing file in textbox.
- html5 File Drag-and-Drop
- Drag And Drop In Javascript
- Drag and Drop in WPF
- Drag and drop in unity
- Basic drag and drop in WinForms
- Simple Drag and Drop in ExtJS
- SSIS <none> text qualifier results in text file containing "_x003C_none_x003E"
- 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
- TrueCrypt原理与系统开发(3):TrueCrypt Mount卸载虚拟磁盘
- 网站上面漂浮的图片移到flas下面的解决方法
- Oracle表空间管理脚本
- 关于机遇
- Hibernate的学习总结(复合主键)
- Drag and Drop text containing file in textbox.
- Jquery特效六:图片自动变换特效
- TrueCrypt原理与系统开发(4):TrueCrypt Mount更改加密卷密码
- test
- java学习之1.5新特性(转)
- 数组名与指针典型面试题的分析(2)
- 正则表达式30分钟入门教程
- android adb shell 不可用的情况
- JVM优化[转]