VB.NET notes to achieve file drag and drop to form

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325724085&siteId=291194637