1. 设置待接收数据控件的AllowDrop属性为True
2.
private void textBox1_DragEnter(object sender, DragEventArgs e)
{//必须设置拖放效果e.Effect = DragDropEffects.Copy;
}private void textBox1_DragDrop(object sender, DragEventArgs e)
{IDataObject dataObject = e.Data;if (dataObject == null) return;//是否能转换成文件if (dataObject.GetDataPresent(DataFormats.FileDrop)){string[] files = (string[])dataObject.GetData(DataFormats.FileDrop);foreach (string file in files){this.textBox1.Text += "文件路径:" + file.ToString()+"\r\n";}}
}