Private Sub
Form1_Load
(
ByVal
sender As
System
.Object,
ByVal
e As
System
.
EventArgs
) Handles MyBase.Load
Me.
AllowDrop
=
True
End Sub
''Create a drag event to implement file drag and drop
Private Sub
Form1_DragEnter
(
ByVal
sender As
Object
,
ByVal
e As
System
.Windows.Forms.
DragEventArgs
) Handles Me.DragEnter
Try
If
e.Data.
GetDataPresent
(DataFormats.
FileDrop
) =
True
Then
e.
Effect = DragDropEffects.Copy
Else
e.
Effect = DragDropEffects.None
End If
Catch ex As
Exception
MessageBox.
Show(ex.
Message)
End Try
End Sub
Private Sub
Form1_DragDrop(
ByVal sender As
Object,
ByVal e As
System.Windows.Forms.
DragEventArgs) Handles Me.DragEnter
Try
Dim
filepath As
String() = e.Data.
GetData(DataFormats.
FileDrop)
For
Each File As
String In filepath
textBox1.
Text =
File
Next
'textBox1.text=filepath(0) 这里还可以这样实现
Catch ex As
Exception
MessageBox.
Show(ex.
Message)
End Try
End Sub