2011-05-20 67 views
1

即时通讯使用C#2.0,我创建了一个资源管理器树,我可以将信息从窗口拖入。现在,当我从即时消息使用的树视图拖动时,它执行DoDragDrop(selectedpath, DragDropEffects.Copy);c#拖放DataObject

当我在我的mainform中捕获事件时,它被列为一个字符串。我能够做这项工作,但我想它来执行同样的方式,它如果我是从我的Windows资源管理器窗口拖动文件如下

Array name = (Array)e.Data.GetData(DataFormats.FileDrop); 
     // Ensure that the list item index is contained in the data. 
     if (e.Data.GetDataPresent(typeof(System.String))) 
     { 

      Object item = (object)e.Data.GetData(typeof(System.String)); 

      // Perform drag-and-drop, depending upon the effect. 
      if (e.Effect == DragDropEffects.Copy || 
       e.Effect == DragDropEffects.Move) 
      { 

       //// Insert the item. 
       //if (indexOfItemUnderMouseToDrop != ListBox.NoMatches) 
       // ListDragTarget.Items.Insert(indexOfItemUnderMouseToDrop, item); 
       //else 
       // ListDragTarget.Items.Add(item); 

      } 
     } 

我试图做的DoDragDrop(新数据对象(selectedfile),DragDropEffects.Copy)但不起作用。

+0

复制功能至少告诉这家伙为什么你失望投他的问题! – Kukoy 2011-05-20 15:25:06

+0

谢谢。我已经搜索了一个答案,但似乎没有找到它。 – charles 2011-05-20 15:26:17

+0

我看不出有什么理由要降低这个问题。 +1 – 2011-05-20 15:30:17

回答

1

DoDragDropDragDropEffects.Copy不会对您的驱动器采取措施,除非您告诉他们。 DragDropEffects.Copy所做的其实是复制程序中的对象,而不是文件本身。

请参阅DragDropEffects上的文档。

你需要管理OnDragDrop事件并使用像File.Copy

+0

那就是我所做的。我找到了一种方法来最终实现以下功能 – charles 2011-05-20 16:07:07