Solved

VB.Net 4.5 Drag and Drop to Explorer

Posted on 2015-01-27
2
554 Views
Last Modified: 2015-01-27
I've looked high and low for a solution to being able to Drag and Drop from a Picturebox to Explorer to copying the file in the folder location.   Take a look at my code below.  I need another set of eyes on it to see what I'm getting wrong here.  Thanks.

Basically, I'm saving the image to a temporary location upon the mouse down event, putting it into the data object, they trying to drop the object upon drop.  Everything seems to work except I get no file.   :(  


    Private Sub Picturebox1_QueryContinueDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.QueryContinueDragEventArgs) Handles PictureBox1.QueryContinueDrag
        'ESC pressed
        If e.EscapePressed Then
            e.Action = DragAction.Cancel
            Return
        End If
        'Drop!
        If e.KeyState = 0 Then
            e.Action = DragAction.Drop
            Kill(strTempFile)
            Return
        End If
        e.Action = DragAction.Continue
    End Sub

    Private Sub Picturebox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown

        m_MouseIsDown = True

    End Sub

    Private Sub Picturebox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

        If m_MouseIsDown Then

            Dim dataObj As DataObject
            dataObj = New DataObject

            strTempFile = Path.GetTempPath & "drawing-" & trItem.IRECID & "-" & TimeOfDay.Hour & TimeOfDay.Minute & TimeOfDay.Second & ".jpg"
            PictureBox1.Image.Save(strTempFile)

            dataObj.SetData(DataFormats.FileDrop, strTempFile)
            DoDragDrop(dataObj, DragDropEffects.Copy)

        End If

        m_MouseIsDown = False

    End Sub
0
Comment
Question by:trelectric
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 40573803
Try this out...

Note that I'm doing a MOVE, which means we don't have to Kill() the temp file unless the operation is cancelled; since the tmp file will actually move to the new location.  Also note the you have to pass a STRING ARRAY to the DataObject even though it is only one item:  
    Private Sub Picturebox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            strTempFile = Path.Combine(Path.GetTempPath, "drawing-" & trItem.IRECID & "-" & TimeOfDay.Hour & TimeOfDay.Minute & TimeOfDay.Second & ".jpg")
            PictureBox1.Image.Save(strTempFile)

            Dim dataObj As New DataObject(DataFormats.FileDrop, New String() {strTempFile})
            PictureBox1.DoDragDrop(dataObj, DragDropEffects.Move)
        End If
    End Sub

    Private Sub Picturebox1_QueryContinueDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.QueryContinueDragEventArgs) Handles PictureBox1.QueryContinueDrag
        If e.Action = DragAction.Cancel Then
            Kill(strTempFile)
        End If
    End Sub

Open in new window

0
 

Author Closing Comment

by:trelectric
ID: 40573972
IT WORKS!  I can stop banging my head against the desk now.  I figured it had to be a string array since I seen other examples as such.  My bad.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question