Place a ListBox on your form, set its AllowDrop property and handle both DragEnter and DragDrop as below.
private void listBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.All;
else
e.Effect = DragDropEffects.None;
}
private void listBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
string[] files = (string[])e.Data.GetData('FileDrop', false);
foreach (string s in files)
{
//just filename
listBox1.Items.Add(s.Substring(1 + s.LastIndexOf(@'\')));
//or fullpathname
// listBox1.Items.Add(s);
}
}
Share with