Senin, 14 Februari 2011

3

[VB.NET] Membuat Program File Explorer Sederhana

  • Senin, 14 Februari 2011
  • Nurkholish Ardi Firdaus
  • Share
  • Huft, habis try out dengan kondisi kepala yang masih berasap aku mencoba untuk cari hiburan. Setelah dipikir-pikir ternyata hiburan yang paling membuat saya terhibur adalam bisa share dengan sobat tentang segala hal yang saya tahu tentang pemrograman, hehehehe. Okedah, izinkan saya kali ini men-share tentang bagaimana cara membuat program File Explorer sederhana menggunakan Visual Basic.NET. Sederhana banget, bahkan anak yang baru lulus dari PAUD juga bisa membuatnya. Oke?? So listen up............



    Deklarasi:
    1 Form
    1 TreeView
    1 ListView


    Atur sedemikian hingga menyerupai tampilan suatu program File Explorer, kayak ini nih... klik untuk memperbesar




    Oke, masukkan source code nya ini gannn..... sruuuupuuutttt....

    ''''''''''''''''''''''''''''''''''''''''''''
    ' Program File Explorer Sederhana
    ' Anak yang buat: Nurkholish Ardi Firdaus
    ' http://www.cr0wja.co.cc
    '
    ''''''''''''''''''''''''''''''''''''''''''''
    Public Class Form1
        Dim Dirs() As IO.DirectoryInfo
        Dim ImageList1 As New ImageList
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            TreeView1.ImageList = ImageList1
            ListView1.SmallImageList = ImageList1
            ListView1.LargeImageList = ImageList1
            ListView1.View = View.LargeIcon
    
            Dim itemDrive As System.IO.DriveInfo
            Dim itemDir As System.IO.DirectoryInfo
            For Each itemDrive In FileIO.FileSystem.Drives
                If itemDrive.IsReady Then
                    With TreeView1.Nodes.Add(itemDrive.Name)
                        For Each itemDir In itemDrive.RootDirectory.GetDirectories
                            .Nodes.Add(itemDir.Name)
                        Next
                    End With
                End If
            Next
            Dim dir As New System.IO.DirectoryInfo(FileIO.SpecialDirectories.ProgramFiles)
            ImageList1.Images.Add("folder", System.Drawing.Icon.ExtractAssociatedIcon(dir.Root.ToString & "\Windows\Explorer.exe"))
        End Sub
    
    
        Private Sub OpenDir(ByVal dirPath As System.IO.DirectoryInfo)
            Dim itemDir As System.IO.DirectoryInfo
            Dim fileItem As System.IO.FileInfo
    
            ListView1.Items.Clear()
    
            On Error Resume Next
    
            ReDim Dirs(itemDir.GetDirectories.Count - 1)
            Dirs = dirPath.GetDirectories.ToArray
    
            For Each itemDir In dirPath.GetDirectories
                ListView1.Items.Add(itemDir.Name).ImageKey = "folder"
            Next
    
            For Each fileItem In dirPath.GetFiles
                Dim newLVitem As New ListViewItem
                If Not ImageList1.Images.ContainsKey(fileItem.Extension) Then
                    Dim newIcon As Icon = SystemIcons.WinLogo
                    newIcon = System.Drawing.Icon.ExtractAssociatedIcon(fileItem.FullName)
                    ImageList1.Images.Add(fileItem.Extension, newIcon)
                End If
                With newLVitem
                    .ImageKey = fileItem.Extension
                    .Text = fileItem.Name
                End With
                ListView1.Items.Add(newLVitem)
            Next
    
            ListView1.EndUpdate()
    
        End Sub
    
        Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
            Dim selDir As System.IO.DirectoryInfo
            selDir = FileIO.FileSystem.GetDirectoryInfo(TreeView1.SelectedNode.FullPath)
            If TreeView1.SelectedNode.GetNodeCount(True) = 0 Then
                Try
                    For Each itemfile In selDir.GetDirectories
                        With TreeView1.SelectedNode.Nodes
                            .Add(itemfile.Name).ImageKey = "folder"
                        End With
                    Next
                Catch
                End Try
            End If
            TreeView1.SelectedNode.Expand()
            OpenDir(selDir)
        End Sub
    
        Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
            If Not ListView1.SelectedItems.Count > 0 Then Exit Sub
            OpenDir(Dirs(ListView1.SelectedItems(0).Index))
        End Sub
    End Class
    '2011 Crowja


    Mudah bukan??? siapa bilang pemrograman itu rumit. Segalanya akan menjadi lebih simple dan seru menggunakan tekhnologi .NET

    Jangan Lupa Komentar Yaa..
    Related Posts Plugin for WordPress, Blogger...

    3 Komentar Untuk “[VB.NET] Membuat Program File Explorer Sederhana”

    Anonim mengatakan...

    Sabtu, 01 Juni 2013 pukul 22.19.00 WIB Reply To This Comment

    gan
    kalo mw pilih jenis thumbnails, detail, kyk gituan di listviewnya gimana yah>?

    truz jg mw ngopy file, ato delete, gmn yah
    thanks gan :D


    Farhan MS mengatakan...
    Minggu, 26 April 2015 pukul 19.28.00 WIB Reply To This Comment

    Kak, kalo di VB6 untuk client server kayak trojan pake Winsock kalo di VB.net apa?


    Farhan MS mengatakan...
    Minggu, 26 April 2015 pukul 19.31.00 WIB Reply To This Comment

    @Mungkin ini sedikit membantu :3 Microsoft VB.net Files IO


    Posting Komentar

    Berikan komentar positif tentang artikel yang sederhana ini niscaya sobat akan mendapatkan balasannya. Hehehe

    Subscribe