Audax321 Posted February 20, 2003 Posted February 20, 2003 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 Quote
*Gurus* divil Posted February 20, 2003 *Gurus* Posted February 20, 2003 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 Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Audax321 Posted February 20, 2003 Author Posted February 20, 2003 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. Quote
*Gurus* divil Posted February 20, 2003 *Gurus* Posted February 20, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Audax321 Posted February 20, 2003 Author Posted February 20, 2003 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... :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.