其他分享
首页 > 其他分享> > 文件拖放到WinForm控件上,文件途径(地址)显示到控件上

文件拖放到WinForm控件上,文件途径(地址)显示到控件上

作者:互联网

先看一下效果,在这里我以TextBox控件为例,其它类型的操作也类似于这样

23.gif

视频讲解地址 https://www.bilibili.com/video/BV1AV4y1M7mR

步骤如下(控件名为textBox1)

1、注册两个事件,代码如下

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 private void textBox1_DragDrop(object sender, DragEventArgs e) {     textBox1.Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); }   private void textBox1_DragEnter(object sender, DragEventArgs e) {     //只允许文件拖放     if (e.Data.GetDataPresent(DataFormats.FileDrop))     {         e.Effect = DragDropEffects.Copy;     }     else     {         e.Effect = DragDropEffects.None;     } }

2、设置控件属性

1 textBox1.AllowDrop = true;

转载请保留 http://www.luofenming.com/show.aspx?id=dbad2a805bc4453698dfdae8aa841bbd

标签:控件,www,文件,Effect,private,textBox1,DataFormats,WinForm
来源: https://www.cnblogs.com/gisoracle/p/16695252.html