[VB6, VB.Net] [Tutorial] How to Drag & Drop in your Form 01-27-2011, 11:21 AM
#1
[VB6, VB.Net] [Tutorial] How to Drag & Drop in your Form
Hello and welcome to this short Tutorial about how to drag and drop from Windows to your Form.
VB6
First we need to set the OLEDropMode property to Manual - 1
Now we will use the OLEDragDrop property of the Control.
In our Example we are using a ListBox names List1
VB.Net
First we need to set the AllowDrop property of a Control to True.
Now we have to use 3 events of the Control for a successful Drag & Drop.
In our Example we are using a ListBox named lstProxy
Now just run your application and drag and drop a file in your Control to test the usage.
Have a great day.
Hello and welcome to this short Tutorial about how to drag and drop from Windows to your Form.

VB6
First we need to set the OLEDropMode property to Manual - 1
Now we will use the OLEDragDrop property of the Control.
In our Example we are using a ListBox names List1
Code:
Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
List1.AddItem Data.Files(1)
End SubVB.Net
First we need to set the AllowDrop property of a Control to True.
Now we have to use 3 events of the Control for a successful Drag & Drop.
- DragDrop
- DragEnter
- MouseDown
In our Example we are using a ListBox named lstProxy
Code:
Private Sub lstProxy_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstProxy.DragDrop
Dim theFile As String = (CType(e.Data.GetData(DataFormats.FileDrop), Array).GetValue(0).ToString)
MsgBox(theFile)
End Sub
Private Sub lstProxy_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstProxy.DragEnter
e.Effect = DragDropEffects.Copy
End Sub
Private Sub lstProxy_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstProxy.MouseDown
lstProxy.DoDragDrop(lstProxy, DragDropEffects.Copy)
End SubNow just run your application and drag and drop a file in your Control to test the usage.
Have a great day.
![[Image: rytwG00.png]](http://i.imgur.com/rytwG00.png)
Redcat Revolution!

![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)