Skip to content

Instantly share code, notes, and snippets.

@jdforsythe
Created July 8, 2014 03:17
Show Gist options
  • Save jdforsythe/a4b5481f7bc0cce20e1c to your computer and use it in GitHub Desktop.
Save jdforsythe/a4b5481f7bc0cce20e1c to your computer and use it in GitHub Desktop.
VB.net drag drop
Public Class uiFrmDragDropTest
Private Sub uiFrmDragDropTest_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Me.AllowDrop = True
' TextBox1.AllowDrop = True
End Sub
'' form drag-drop
Private Sub uiFrmDragDropTest_DragEnter(sender As Object, e As DragEventArgs) Handles Me.DragEnter
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub uiFrmDragDropTest_DragDrop(sender As Object, e As DragEventArgs) Handles Me.DragDrop
Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
For Each path In files
TextBox1.Text &= vbCrLf & path
Next
End Sub
'' textbox drag-drop
Private Sub TextBox1_DragEnter(sender As Object, e As DragEventArgs) Handles TextBox1.DragEnter
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub TextBox1_DragDrop(sender As Object, e As DragEventArgs) Handles TextBox1.DragDrop
Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
For Each path In files
TextBox1.Text &= vbCrLf & path
Next
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment