Filtrare i D&D.

domenica 07 dicembre 2008 - 09.33

xxtr93 Profilo | Junior Member

Ciao!

Sto creando un applicazione che usa il metodo del D&D per visualizzare il percorso del file spostato su un textbox.


Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop

Try
Dim str As String = CType(e.Data.GetData(DataFormats.FileDrop), Array)(0)

str = IO.Path.GetDirectoryName(str) & "\" & IO.Path.GetFileName(str)
If ComboBox1.Text <> "" Then
TextBox1.Text = str
Else
MsgBox("Scegliere l'unità a cui cambiare l'icona", MsgBoxStyle.Exclamation)
End If

Catch ex As Exception
MsgBox("Impossibile trovare il file!", MsgBoxStyle.Critical)
End Try


End Sub

Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter

Try
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
Catch ex As Exception

End Try
End Sub


Il problema è: Come posso filtrare i file spostati sul textbox, io voglio solo i file con estensione ".ico" ma non so come fare.

0v3rCl0ck Profilo | Guru

>Ciao!

Ciao

>
>Sto creando un applicazione che usa il metodo del D&D per visualizzare
>il percorso del file spostato su un textbox.
>
>
>Il problema è: Come posso filtrare i file spostati sul textbox,
>io voglio solo i file con estensione ".ico" ma non so come fare.

Vorresti non visualizzare niente nella textbox, ed eventualmente una messagebox, se vi viene trascinato un file che non ha estensione .ico? Ho capito bene?



-------------------------------------------------------------------
Michael Denny
Senior Software Developer - Microsoft Framework (C# ASP.NET VB.NET)
http://blogs.dotnethell.it/Regulator/

xxtr93 Profilo | Junior Member

Esatto! Proprio così! Sai come si fa?

0v3rCl0ck Profilo | Guru

Puoi utilizzare il metodo: Path.GetExtension(string path)

Ti ritorna una stringa contenente l'estensione del file compreso del punto '.'

Es.: Path.GetExtension("C:\pippo.txt") Ritornerà ".txt"

Oppure puoi utilizzare anche l'oggetto FileInfo:

Dim fi2 As FileInfo = New FileInfo(path2)

fi2.Extesion

-------------------------------------------------------------------
Michael Denny
Senior Software Developer - Microsoft Framework (C# ASP.NET VB.NET)
http://blogs.dotnethell.it/Regulator/

xxtr93 Profilo | Junior Member

Hey! Ma 6 un genio? Funziona alla perfezione!!!
Grazie, non immagini quanto mi sia servito il tuo aiuto.
Ciao

0v3rCl0ck Profilo | Guru

>Hey! Ma 6 un genio? Funziona alla perfezione!!!
>Grazie, non immagini quanto mi sia servito il tuo aiuto.
>Ciao

Bene sono contento

Alla prossima
Ciaooo

-------------------------------------------------------------------
Michael Denny
Senior Software Developer - Microsoft Framework (C# ASP.NET VB.NET)
http://blogs.dotnethell.it/Regulator/
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-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5