- private void txtSrcFname_DragEnter(object sender, DragEventArgs e)
- {
- if (e.Data.GetDataPresent(DataFormats.FileDrop))
- e.Effect = DragDropEffects.All;
- else
- e.Effect = DragDropEffects.None;
- }
- private void txtSrcFname_DragDrop(object sender, DragEventArgs e)
- {
- string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
- txtSrcFname.Text = "";
- if (s.Length > 0)
- txtSrcFname.Text = s[0];
- }
复制代码
为textbox添加以上2个事件就可以通过拖拽获取文件路径了 |