文件拖放到WinForm控件上,文件途径(地址)显示到控件上
先看一下效果,在这里我以TextBox控件为例,其它类型的操作也类似于这样

视频讲解地址 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
浙公网安备 33010602011771号