Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.Net 4.5 Drag and Drop to Explorer

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

Independent Software Vendors: 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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month6 days, 7 hours left to enroll

782 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