2016-03-03 81 views
3

我有一個顯示目錄內容的列表視圖。我已啓用拖放到列表視圖,以便用戶可以從Windows資源管理器中拖動文件,並將其放入列表視圖中。然後,我將這些文件複製到列表視圖中顯示的目錄中。從剪貼板中獲取複製的郵件

如果您將電子郵件從Outlook拖放到桌面或Windows資源管理器中的文件夾中,它會創建電子郵件的.msg文件。 用戶現在想要從Outlook拖動電子郵件並將其放入列表視圖。

當一封電子郵件在列表視圖中出現毒品時,它不會將其視爲有效的拖放對象。光標是一個帶有一條直線的圓,而不是放置事件光標。

listView1_DragEnter事件中,我有

 if (e.Data.GetDataPresent(DataFormats.FileDrop)) 
     { 
      e.Effect = DragDropEffects.All; 
     } 
     else 
     { 
      e.Effect = DragDropEffects.None; 
     } 

我已經試過DataFormats.HTML但這並不見什麼砸無論是。有任何想法嗎?

電子郵件從Outlook中的列表部分拖出。
enter image description here

回答

2

在ListView的DragEnter事件,返回以下DragDropEffects

private void listView_DragEnter(object sender, DragEventArgs e) 
{ 
    e.Effect = DragDropEffects.All; 
} 

解壓和讀取的DragDrop事件中的Outlook郵件(S),我建議使用this庫。這是非常容易使用:

private void listView_DragDrop(object sender, DragEventArgs e) 
{ 
    OutlookDataObject dataObject = new OutlookDataObject(e.Data); 

    //get the names and data streams of the files dropped 
    string[] filenames = (string[])dataObject.GetData("FileGroupDescriptor"); 
    MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents"); 

    for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++) 
    { 
     string filename = filenames[fileIndex]; 
     MemoryStream filestream = filestreams[fileIndex]; 

     OutlookStorage.Message message = new OutlookStorage.Message(filestream); 

     // do whatever you want with "message" 

     message.Dispose(); 
    } 
}