DragDrop files

  • Thread starter Thread starter Roger Uribe
  • Start date Start date
R

Roger Uribe

It was easy in VB6...

how can i retrieve the name(s) of files dropped onto a vb.net control from
windows explorer

it'll be easy in vb.net too ... when i know the answer!!

thanks
roger
 
Roger,

An old sample that I made from a sample that is on MSDN

\\\Needs 2 textboxes on a form
Private MouseIsDown As Boolean = False
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox2.AllowDrop = True
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
MouseIsDown = True
Me.TextBox1.Cursor = Cursors.Hand
End Sub
Private Sub TextBox1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseMove
If MouseIsDown Then
TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Copy)
End If
MouseIsDown = False
Me.TextBox1.Cursor = Cursors.Default
End Sub
Private Sub TextBox2_DragEnter(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter
If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub TextBox2_DragDrop(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop
TextBox2.Text = e.Data.GetData(DataFormats.Text).ToString
End Sub
///

Some links
http://msdn.microsoft.com/library/d.../vbcon/html/vbconDragDropClipboardSupport.asp

http://msdn.microsoft.com/library/d.../en-us/dv_vstechart/html/vbtchimpdragdrop.asp

I hope this helps?

Cor
 
Roger,
Do you want the list of files or the text of the files?

It appears that Cor gave you a sample with the text of a file.

To get the list of files you need to use DataFormats.FileDrop instead of
DataFormats.Text:

Something like:

Private Sub TextBox2_DragDrop(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop
Dim files() As String
files = DirectCast(e.Data.GetData(DataFormats.FileDrop), String())
For Each file As String in files
TextBox2.Text &= file & ControlChars.CrLf
Next
End Sub

The DataFormats.FileDrop is an array of strings, where each element is the
file name that you are dropping from Windows Explorer.

Hope this helps
Jay
 
Jay,
It appears that Cor gave you a sample with the text of a file.

That why I gave the links with it, my idea was that this was easier to test.
Now I think I should have writen that in my text.

However your addition is a good one to make it complete.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top