Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to implement a Panel in Winform , when a user drags a file on it (a simple .txt file) , it should accept it and stores its path into some variable called filepathname etc. which can be used earlier. I could find examples on how to implement drag and drop but not on how to get the path and store it for use later in the program. Using : Visual Studio 2008 - Vb.net

Thanks!
Posted

1 solution

Solved by me looking up through some sites. I dont know why i couldn't find them earlier!

VB
Private Sub dropdpanel_DragEnter(sender As Object, e As DragEventArgs) Handles dropdpanel.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.All
        End If
    End Sub

    Private Sub dropdpanel_DragDrop(sender As Object, e As DragEventArgs) Handles dropdpanel.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim MyFiles() As String


            ' Assign the files to an array.
            MyFiles = e.Data.GetData(DataFormats.FileDrop)
            'If there are more than one file, set first only
            'If you want another restrictment, please edit this.
            filepathname = MyFiles(0)

        End If
    End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900