2016-11-28 31 views
0

我有一個WinForms應用程序,它顯示列表框中某個文件夾內的文件(比如D:\ work)。我需要將drag-n-drop屬性添加到我的應用程序中,以便可以拖動一些文件並將其放到我的桌面上。當我拖動一個文件,將其放到桌面上時,最小化我的窗體表格

所以我成功地做到這一點,但我希望我的形式,以儘量減少或更好,發送到備份(如果有打開的窗口中刪除該文件中它

我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; 
} 

感謝提前:)

+0

你是什麼意思與「如果有一個打開的窗口砸我的文件」? – GuidoG

+0

最小化你自己的窗口並不是很成功。現有的用於拖放的UX用於將拖動光標懸停在任務欄按鈕上或任務欄上的「顯示桌面」鏈接上。嘗試一下。 –

回答

相關問題