I searched high and low for a way in VB.NET to be able to drag and drop Outlook emails onto a control or form. The closest thing I could find was written in C# and posted by FabioPoroli.
What I did is convert the code to VB.NET and modify it to work with any control or a form. (The original code created a custom control to capture the dropped items.)
The only known issue is when you drop multiple files from the file system it will only grab the first file. (I'm still trying to resolve this problem any help would be greatly appreciated.)
The code is attached in the Zip file and below is how to implement the code.
VB.NET Code:
Public Class Form1 Private WithEvents clsDropProcess As DragDropProcess.DragDropProcess 'This is so we can handle the drop event Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.ListBox1.AllowDrop = True 'You have to set AllowDrop on the control you wish to use to [i]True[/i] clsDropProcess = New DragDropProcess.DragDropProcess(ListBox1) 'Create a new instance of the class and pass the control that you want to allow files to be dropped on AddHandler clsDropProcess.DroppedByteArrayAvailable, AddressOf DropEvent 'Add a handler to get the files/emails that have been dropped End Sub Public Sub DropEvent(ByVal sender As Object, ByVal filename As String, ByVal bytes As Byte()) 'This is the event that will fire for each file/email that is dropped. 'Add code to do whatever you want with the file. End Sub End Class
I hope everyone finds this as useful as I have.




Reply With Quote