Hello everyone.
I really don't know where to post this, but, anyways.... here is my problem....
I have built a program that generates a waveform for a .wav or .wave file....
but the music clip can only go in through the "file, open, and blah blah blah"
I really want to make it so the audio clip can be dragged onto my panel (the panel that generates the waveform)... from my desktop, ore some other location. How do i do this?
(I have tried many times, but failed)... you can help me in the following codes "vb.net code___c___c#___c++" big thanks...

P.S i know how to drag and drop items from text boxes... so here is my code for that..
Public Class frmDragDrop

Private Sub textBoxMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tbDragFrom.MouseDown
tbDragFrom.DoDragDrop(tbDragFrom.Text, DragDropEffects.Move)
End Sub

Private Sub textBoxDragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles tbDragTo.DragEnter
If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Move
End If
End Sub

Private Sub textBoxDragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles tbDragTo.DragDrop
tbDragTo.Text &= e.Data.GetData(DataFormats.Text).ToString
tbDragFrom.Text = ""
End Sub

Recommended Answers

All 4 Replies

The following code will allow you to drop files on your form and get their full path.
Since it will return a file's full path, the rest should be easy.

The code had to be slightly modified for it to respond properly, and originated from here.

Imports System.IO
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.AllowDrop = True
        AddHandler Me.DragEnter, AddressOf Form1_DragEnter
        AddHandler Me.DragDrop, AddressOf Form1_DragDrop
    End Sub

    Private Sub Form1_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs)
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub Form1_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs)
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim filePaths As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
            For Each fileLoc As String In filePaths
                '////////////////////////////////////////////////////
                If File.Exists(fileLoc) Then
                    MsgBox("Full Path: " & vbNewLine & Path.GetFullPath(fileLoc))
                End If
                '////////////////////////////////////////////////////
            Next
        End If
    End Sub
End Class
commented: Great coding! +1

so i just put this code into my panel? or into form 1?

You can move the code to the appropriate events for the Panel and set AllowDrop to True in the Panel's Properties, or you can just simply modify the Form1_Load event.

Example:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Panel1.AllowDrop = True
        AddHandler Panel1.DragEnter, AddressOf Form1_DragEnter
        AddHandler Panel1.DragDrop, AddressOf Form1_DragDrop
    End Sub

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.