Drag and Drop to get filepath

February 9, 2009 on 6:04 pm | In Programming | 1 Comment

These pieces of code allow you to drag and drop a file into a picturebox and it will display the full path in a TextBox.

Private Sub exelreader_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
‘exelreader is the Form name and pb is the name of the PictureBox
pb.AllowDrop = True
End Sub

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

Private Sub pb_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pb.DragDrop
Dim filePaths As String() = {“”}
Try
filePaths = CType(e.Data.GetData(DataFormats.FileDrop), String())
Catch ex As Exception
TextBox1.Text = ex.Message
TextBox1.Text &= “Error Doing Drag/Drop”
End Try
For Each filename In filePaths
TextBox1.Text = filename
Next
End Sub

1 Comment »

RSS feed for comments on this post. TrackBack URI

  1. […] View full post on Metallica’s blog […]

    Pingback by Drag and Drop to get filepath | Computer Security Articles — May 3, 2010 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^