Hi, ich mal wieder,
mit ein wenig "Suche" und "Hilfe" aus diesem Forum und etwas eingenem habe ich das, was machen wollte hinbekommen. Wenn es noch jemand gebrauchen kann, hier ist der Code, wie er jetzt aussieht und das macht, was er soll.
Private Sub Form1Load(sender As System.Object, e As System.EventArgs)
Item = - 1
' Dirsearch(New DirectoryInfo("E:\PCS"), "*.WMF")
Dirsearch(New DirectoryInfo("I:\Clipart"), "*.WMF")
Treeview1.ImageList = Imagelist1
End Sub
Sub DirSearch(ByVal StartDir As DirectoryInfo, ByVal SuchName As String)
Dim Fi As FileInfo
Dim z As Integer = 0
Dim wert As Integer
For Each Fi In StartDir.GetFiles
If Fi.Extension = ".WMF" Then
End If
Next
Dim Di As DirectoryInfo
For Each Di In StartDir.GetDirectories
gefunden = 0
DirSearch(Di, SuchName)
AddToTreeView(TreeView1,Di.FullName)
Next
End Sub
Sub FindFirstWMF(ByVal StartDir As DirectoryInfo, ByVal SuchName As String)
Dim Fi As FileInfo
Dim z As Integer = 0
For Each Fi In StartDir.GetFiles
If Fi.Extension <> ".WMF"
z = z + 1
End If
If Fi.Extension = ".WMF" Then
gefunden += 1
File = IO.Directory.GetFiles(StartDir.FullName)(z).ToString
Dim img As Image = Image.FromFile(File)
Dim bmp As Bitmap = New Bitmap(img, 100,100)
Imagelist1.Images.Add(bmp)
label1.Text = File
listbox1.Items.Add(File)
z = 0
Exit For
End If
Next
Dim Di As DirectoryInfo
For Each Di In StartDir.GetDirectories
DirSearch(Di, SuchName)
If gefunden > 0
Exit For
End If
Next
End Sub
Public Sub AddToTreeView(ByVal xTreeView As TreeView, ByVal Pfad As String)
Dim Verz As DirectoryInfo
Dim TN As New TreeNode
Dim splt() As String
splt = Split(Pfad, "\")
If Not ExistsNode(TreeView1.Nodes, splt(0)) Then
FindFirstWMF(New DirectoryInfo(Pfad), "*.WMF")
Messagebox.Show(splt(0))
TN = New TreeNode
TN.Text = splt(0)
TreeView1.Nodes.Add(TN)
Item += 1
TN.ImageIndex = Item
TN.Tag = Item
LastTreeNode = TN
End If
If splt.Length > 1 Then
Dim i As Integer
For i = 1 To splt.Length - 1
If Not ExistsNode(LastTreeNode.Nodes, splt(i)) Then
FindFirstWMF(New DirectoryInfo(Pfad), "*.WMF")
TN = New TreeNode
TN.Text = splt(i)
LastTreeNode.Nodes.Add(TN)
Item +=1
TN.ImageIndex = Item
TN.Tag = Item
LastTreeNode = TN
End If
Next
End If
End Sub
Private LastTreeNode As TreeNode
Private Function ExistsNode(ByVal xNode As TreeNodeCollection, ByVal Name _
As String) As Boolean
ExistsNode = False
Dim y As TreeNode
For Each y In xNode
If y.Text = Name Then
ExistsNode = True
LastTreeNode = y
Exit Function
End If
Next
End Function
End Class
End NamespaceFalls jemand noch Verbesserungsmöglichkeiten findet, bin ich für alles dankbar - bin ja schliesslich noch Anfänger in VB.Net
Gruss
Eckhard! |