Nein, nicht alles. Einfach nur ein kl. Teil davon. Da es ist sonst etwas schwer ist/war, dein Vorhaben richtig zu verstehen.
Ich hab mal schnell ein kl. Beispiel erstellt. Sozusagen die Version 0.1
Du benötigst für diesen Code ein TreeView, ein Button und ein Label (auf deiner Form). Hier der Code:
Option Explicit On
Option Strict On
Public Class Form1
'// DesignerRegion
Dim imgList As ImageList
Dim idx As Integer
Dim imgRoot As String = "D:\images"
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim root As New MyTreeNode("My Images", MyTreeNode.NodeType.IsRootNode, _
0)
Me.imgList.Images.Clear()
idx = 0
imgList.Images.Add(New Bitmap(4, 4))
Me.TreeView1.ImageList = imgList
Me.TreeView1.BeginUpdate()
Me.TreeView1.Nodes.Add(root)
Me.SearchImages(imgRoot, root.Nodes)
Me.TreeView1.EndUpdate()
End Sub
Private Sub FillImageListAndNode(ByVal fileName As String, _
ByRef NodeColl As TreeNodeCollection)
Dim img As Image = Image.FromFile(fileName)
imgList.Images.Add(img)
idx += 1
NodeColl.Add(New MyTreeNode(fileName, MyTreeNode.NodeType.IsImage, idx))
End Sub
Private Sub GetImages(ByVal Dir As String, _
ByRef NodeColl As TreeNodeCollection)
For Each f As String In IO.Directory.GetFiles(Dir)
FillImageListAndNode(f, NodeColl)
Next
End Sub
Private Sub SearchImages(ByVal Dir As String, _
ByRef NodeColl As TreeNodeCollection)
Dim tn As New MyTreeNode(Dir, MyTreeNode.NodeType.IsFolder, 0)
GetImages(Dir, tn.Nodes)
NodeColl.Add(tn)
For Each d As String In IO.Directory.GetDirectories(Dir)
SearchImages(d, tn.Nodes)
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
imgList = New ImageList
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As _
System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Dim tn As MyTreeNode = CType(Me.TreeView1.SelectedNode, MyTreeNode)
Me.Label1.Text = "INFO: " + tn.ToString()
End Sub
End Class
Public Class MyTreeNode
Inherits TreeNode
Public TreeNodeType As NodeType
Public Sub New(ByVal Text As String, _
ByVal NodeType As NodeType, _
ByVal ImageIndex As Integer)
Me.Text = Text
Me.TreeNodeType = NodeType
Me.ImageIndex = ImageIndex
Me.SelectedImageIndex = Me.ImageIndex
End Sub
Public Enum NodeType
IsFolder
IsImage
IsRootNode
End Enum
Public Overrides Function ToString() As String
Return String.Format( _
"Text: {0} " + _
"ImageIndex: {1} " + _
"NodeType: {2} ", _
Me.Text, _
Me.ImageIndex, _
Me.TreeNodeType.ToString() _
)
End Function
End ClassIch denke, das ist eine gute Basis. Den Rest müsstest du/wir ggf. anpassen/ändern.
Die jetzige Ordnerstruktur:
D:\IMAGES
+---img1
| +---img1
| \---img2
+---img2
| +---img1
| \---img2
\---img3
+---img1
\---img2 In den Unterordnern img1 und img2 befinden sich bspw. irgendwelche Bilder.
PS: Du kannst in der Kosnole ohne Prob. kopieren. Einfach Rechtsklick mit der Maus, "markieren" auswählen, Text auswählen und Return drücken. Jetzt befindet sich der Text in der Zwischenablage.  |