Drag & Drop da cartella a textbox

lunedì 01 dicembre 2008 - 11.12

xxtr93 Profilo | Junior Member

Ciao

Vorrei visualizzare il path di una cartella su un textbox tramite il Drag & Drop.

Per esempio:

Dentro DragEnter ci metto:

If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If

e dentro DragDrop ci metto:

Dim a As String()
a = e.Data.GetData(DataFormats.FileDrop)
Console.WriteLine(a(0))

prendo un file dal Desktop lo trascino sulla Form e rilascio il mouse.
Quindi appare nella finestra di Output, il path al file.

Io voglio che questo accada con una cartella e che il path venga visualizzato sul textbox.

Aiutatemi!!!

aiedail92 Profilo | Expert

Ciao

Ormai hai già fatto tutto... Se vuoi che il file possa essere trascinato solo sulla TextBox basta che gestisci i suoi eventi:

Private Sub tuaTextBox_DragEnter(ByVal sender As System.Object, ByVal e As DragEventArgs) _ Handles tuaTextBox.DragEnter If e.Data.GetDataPresent(DataFormats.FileDrop) Then e.Effect = DragDropEffects.Copy Else e.Effect = DragDropEffects.None End If End Sub Private Sub tuaTextBox_DragDrop(ByVal sender As System.Object, ByVal e As DragEventArgs) _ Handles tuaTextBox.DragDrop Dim str As String = CType(e.Data.GetData(DataFormats.FileDrop), Array)(0) ''Se ti serve solo la cartella fai così 'str = IO.Path.GetDirectoryName(str) tuaTextBox.Text = str End Sub

Luca

xxtr93 Profilo | Junior Member

FANTASTICO!!! 6 UN GENIO

Grazie
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5