新建文本框txtSrcFname,设计其AllowDrop为true,处理DragEnter、DragDrop 事件。
源码:
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);
this.textBox1.Text = "";
if (s.Length > 0)
textBox1.Text = s[0];
}