设置Form/控件的属性 AllowDrop为true,此方法适用于任何控件 private void Form1_DragDrop(object sender, DragEventArgs e) { string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
//获取多个文件或者文件夹
//string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop); MessageBox.Show(path); } private void Form1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Link; else e.Effect = DragDropEffects.None;
}