Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I wanted to initialize a drag from my program as a file... Kind of like Windows Explorer does. I found a way to do this on VB6 (see code below). But I'm not sure how to add this to my program in VB.NET. Currently I have it dragging a string containing the path to the file.

 

Here is the VB6 code:

Private Sub Picture1_OLEStartDrag(Data As DataObject, AllowedEffects As Long)
 ' this evant allows us to implement dragging *from* our picturebox to other drag targets in the system
 
 ' make sure there is a file name in the tag property (you would probaby want to use a "file
 ' exists" routine here but for this demo we are doing it simply)
 If Picture1.Tag <> "" Then
   On Error GoTo EH
   
   ' set the drop effect to create a copy of the file wherever it get's dropped
   AllowedEffects = vbDropEffectCopy
   
   With Data
     ' clear the contents of the data object
     .Clear
     ' tell the data object we will be dragging files
     .SetData , vbCFFiles
     ' add the file name that we storred in the tag eairler
     .Files.Add Picture1.Tag
   End With
 End If
 
ExitNow:
 Exit Sub
 
EH:
 Err.Clear
 MsgBox "Unable to initiate drag."
 Resume ExitNow
 
End Sub

  • *Gurus*
Posted

I think something like this is what you need:

 

   Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
       Dim s(0) As String
       Dim d As DataObject

       s(0) = "c:\test.txt"
       d = New DataObject(DataFormats.FileDrop, s)

       PictureBox1.DoDragDrop(d, DragDropEffects.Copy Or DragDropEffects.Move)
   End Sub

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

That is what I want, but it doesn't work. I made a file search utility that searches specified directories for files... I want to be able to drag (copy) these files onto the desktop (or any other folder) from their current location.

 

I also want any mp3s found to be dragged into WinAmp. Dragging a string containing the path doesn't work. I think WinAmp requires a path to be dragged as a file.

  • *Gurus*
Posted

Sorry, that code works perfectly. Replacing the path with the full path to an MP3 worked, dragging it in to winamp. When you drag files, all you are really dragging is a string array of paths anyway.

 

If you're using a listview as your source for dragging multiple files, it has an ItemDrag event to cater for multiple items being dragged, so you use that instead of MouseDown.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Woohoo, just checked my code, I forgot to replace the path in the listbox.dodragdrop command with the variable for the data object .... it worked...

 

Thanks... :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...