visual basic

VB Drag & Drop Files

From this question on Stack Overflow.

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Imports System.Windows.Forms
 
Public Class Form1
 
    Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles TextBox1.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.All
        End If
    End Sub
 
    Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles TextBox1.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim MyFiles() As String
            Dim i As Integer
            MyFiles = e.Data.GetData(DataFormats.FileDrop)
            TextBox1.Text = MyFiles(i)
        End If
    End Sub
 
End Class