Me.AddFile(New DirectoryInfo(f.SelectedPath), nodeTemp) Me.ResumeLayout(False) End If End Sub
Private Sub AddFile(ByVal dirPath As DirectoryInfo, ByVal node As TreeNode) Dim tempHandler As New AddFileHandler(AddressOf Me.AddFileToTreeNode) For Each dir As DirectoryInfo In dirPath.GetDirectories() Dim nodeTemp As TreeNode = CType(Me.Invoke(tempHandler, New Object() {dir.Name, CLASSIO.Directory, node}), TreeNode) Me.AddFile(dir, nodeTemp) Next For Each file As FileInfo In dirPath.GetFiles("*.dll") Me.Invoke(tempHandler, New Object() {file.Name, CLASSIO.File, node}) Next End Sub
Private Function AddFileToTreeNode(ByVal str As String, ByVal cls As CLASSIO, ByVal node As TreeNode) As TreeNode Dim nodeTemp As New TreeNode(str) nodeTemp.ImageIndex = CInt(cls) node.Nodes.Add(nodeTemp) nodeTemp.SelectedImageIndex = nodeTemp.ImageIndex Return nodeTemp End Function
Private Function AddFileToTreeview(ByVal str As String) As TreeNode Dim nodeTemp As New TreeNode(str) Me.TreeView1.Nodes.Add(nodeTemp) Return nodeTemp nodeTemp.SelectedImageIndex = CInt(CLASSIO.Directory) End Function
Private Sub btnOpenBrower_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenBrower.Click '多线程 Dim t As Threading.Thread = New Threading.Thread(AddressOf Me.OpenBrower) t.Start()
'单线程 'Me.OpenBrower() End Sub End Class Public Enum CLASSIO File = 1 Directory = 0 End Enum Public Delegate Function AddFileHandler(ByVal str As String, ByVal cls As CLASSIO, ByVal Node As TreeNode) As TreeNode Public Delegate Function AddTreeNodeHandler(ByVal str As String) As TreeNode |