For drop:
For drag and drop:
1) Set the AllowDrop property of your form to True
2) Create a handler for both the DragEnter and DragDrop events of your form.
3) In the DragEnter handler, add the following line of code:
e.Effect = DragDropEffects.Move;
4) In the DragDrop handler, add the following:
string[] files = (string[]) e.Data.GetData(DataFormats.FileDrop);
if (files != null)
{
foreach (string file in files)
{
Console.WriteLine(file);
}
}
(this shows file drop, there are other formats available)
For Drag:
Handle MouseMove and create a StringCollection, then the DataObject, then do the DragDrop:
private void dgvTracks_MouseMove(object sender, MouseEventArgs e)
{
DataGridView dgv = sender as DataGridView;
System.Collections.Specialized.StringCollection filePath = new System.Collections.Specialized.StringCollection();
foreach (DataGridViewRow row in dgv.SelectedRows)
{
filePath.Add((string)row.Cells["Path"].Value);
}
DataObject dataObject = new DataObject();
dataObject.SetFileDropList(filePath);
dgv.DoDragDrop(dataObject, DragDropEffects.Copy);
}
This provides a list of files from a DataGridView.
It's a similar procedure depending on what you want to drag out of your control(s)