I have a WinForms application that displays the files inside some folder in a listbox (let's say D:\work). I need to add drag-n-drop property to my application, so that I can drag some files and drop it on my desktop.
So I managed to do that, but I want my form to minimize or better, sent to back (if there is an opened window to drop the file in it.
My listBox_mouseDown:
private void listBox_MouseDown(object sender, MouseEventArgs e)
{
ListBox listBox = (ListBox)sender;
int index = listBox.IndexFromPoint(e.Location);
if (index >= 0)
{
Item selItem = (Item)listBox.Items[index];
if (selItem != null)
{
if (e.Button == MouseButtons.Left)
{
clickPoint = Cursor.Position;
string[] filesToDrag = { selItem.path };
listBox.DoDragDrop(new DataObject(DataFormats.FileDrop, filesToDrag), DragDropEffects.Copy);// Here I want the window to minimize
diff.X = Math.Abs(clickPoint.X - Cursor.Position.X);
diff.Y = Math.Abs(clickPoint.Y - Cursor.Position.Y);
if (diff.X < 20 && diff.Y < 20)
listBox_MouseClick(sender, e);
}
else
{
if (e.Button == MouseButtons.Right)
{
selItem = (Item)listBox.Items[listBox.IndexFromPoint(e.X, e.Y)];
if (selItem.isFile() && !listBoxFavorites.Items.Contains(selItem))
listBoxFavorites.Items.Add(selItem);
}
}
}
}
}
listBox_DragOver:
private void listBox_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
Thanks in advance! :)