C# WinForm拖入文件到窗体,得到文件路径

时间:2014-05-31 03:20:59   收藏:0   阅读:753
bubuko.com,布布扣

private void textBox1_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] rs = (string[])e.Data.GetData(DataFormats.FileDrop); MessageBox.Show(rs[0]); } } private void Form1_DragEnter_1(object sender, DragEventArgs e) { //只允许文件拖放 if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Copy; } else { e.Effect = DragDropEffects.None; } }
bubuko.com,布布扣

窗体上添加以上2个事件即可。DragEnter、DragDrop

C# WinForm拖入文件到窗体,得到文件路径,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!