Vitajte na [www.pocitac.win] Pripojiť k domovskej stránke Obľúbené stránky
Spustite program Microsoft Visual Basic Express , kliknite na tlačidlo " Nový projekt ... " V ľavej table obrazovky a vyberte "Windows Forms . " Kliknite na tlačidlo " OK " .
2
Double - kliknite na " TreeView " na " Toolbox " paneli pridať nový ovládací prvok TreeView . Double - kliknite na " Form1 " otvorte modul " Form1.vb " .
3
Zadajte nasledujúce pod " Form1_Load " definovať zdrojový cestu začať hľadať a pridať prvý uzol :
Dim frstNode As New System.Windows.Forms.TreeNode ( )
frstNode.ImageIndex = 0
frstNode.SelectedImageIndex = 0
frstNode . text = " G : \\ "
TreeView1.Nodes.Add ( frstNode )
4
Kliknite na " Form1.vb [ Návrh ] " a dvakrát kliknite na ovládací prvok TreeView " " . Zadajte nasledujúce pridať adresárov a súborov na kontrolu:
Dim obj ako nový proces
Text = e.Node.Text
Ak Directory.Exists ( e.Node . Text ) = True Then
GetFiles ( e.Node , e.Node.Text )
End If
Ak File.Exists ( e.Node.Text ) = true Then
obj.Start ( e.Node.Text , AppWinStyle.MaximizedFocus )
End If
5
Zadajte nasledujúce pod " Public Class Form1 " na vytvoriť nový podprogram , ktorý bude hľadať pre adresáre a súbory :
Private Sub GetFiles ( byval pNode ako TreeNode , byVal dirStr As String )
Dim MyDir ako Directory
Dim iCnt as Integer
iCnt = 0 ( myDir.GetDirectories ( dirStr ) Dĺžka . ) - 1
Dim childNode ako novú _
TreeNode ( myDir.GetDirectories ( dirStr ) ( iCnt ) . toString , 1 , 0 )
iCnt = pNode.Nodes.Add ( childNode )
Ďalšie iCnt
iCnt = 0 ( myDir.GetFiles ( . dirStr , " . * xls " ) Dĺžka ) - . 1
Dim childNode ako novú _
TreeNode ( myDir.GetFiles ( dirStr , " . * xls " ) ( iCnt ) toString , 2 , 2 )
iCnt = pNode.Nodes.Add ( childNode )
Ďalšie iCnt
pNode.Expand ( )
End Sub
praha 6
Stlačte " F5 " spustiť podprogram potom kliknite na súbor programu Excel a otvorte ju .