?
Solved

VB.Net 4.5 Drag and Drop to Explorer

Posted on 2015-01-27
2
Medium Priority
?
588 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 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