Drap Drop Question

  • Thread starter Thread starter pmclinn
  • Start date Start date
P

pmclinn

Does anyone have some sample code that would show me how to drag and
..doc or exe file to a drop target and then extract the file path on
drop?
 
Here is something I did which places dropped items in a CheckListBox. The
code is more or less a copy from a webpage (don't remember were from).

Private Sub Form1_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
End If
End Sub

Private Sub Form1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim draggedFiles As String() =
CType(e.Data.GetData(DataFormats.FileDrop), String())
For Each strFileName As String In draggedFiles
With ListBox1
.Items.Add(strFileName)
.SetSelected(.Items.Count - 1, True)
.SetItemChecked(.SelectedIndex, True)
End With
Next
Me.ActiveControl = ListBox1
End If
End Sub

Hope this helps you.
 
Back
Top