| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net实例分析 >> 其他 >> 实例分析正文
最新推荐 更多内容
查看目录树(VB2010实例)
查看目录树(VB2010实例)
作者:Akyao    来源:乐博网收集     更新时间:2011-5-17

本文演示查看目录树,包含两个与 Windows 资源管理器类似、具有拆分窗口的窗体,来自乐博网。

代码分目录扫描 目录树查看  列目录  查看文件 等

如果你想下载本文的源代码RAR压缩集合包  请访问
VB2010源代码集合包(芋头糕)    http://www.lob.cn/code/utility/2795.shtml
特别感谢网友 芋头糕 将此资源提供乐博网分享,欢迎加入 40797788 的.Net超级qq群交流。

包含两个与 Windows 资源管理器类似、具有拆分窗口的窗体

目录树查看代码如下:

' Copyright (c) Microsoft Corporation. All rights reserved.
Imports System.IO

Class DirectoryTreeView
    Inherits TreeView

    ' This is the Class constructor.
    Public Sub New()
        ' Make a little more room for long directory names.
        Me.Width *= 2

        ' Get images for tree.
        Me.ImageList = New ImageList()
        With Me.ImageList.Images
            .Add(My.Resources.FLOPPY)
            .Add(My.Resources.CLSDFOLD)
            .Add(My.Resources.OPENFOLD)
        End With

        ' Construct tree.
        RefreshTree()
    End Sub

    ' Handles the BeforeExpand event for the subclassed TreeView. See further
    ' comments about the Before_____ and After_______ TreeView event pairs in
    ' /DirectoryScanner/DirectoryScanner.vb.
    Protected Overrides Sub OnBeforeExpand(ByVal tvcea As TreeViewCancelEventArgs)
        MyBase.OnBeforeExpand(tvcea)

        ' For performance reasons and to avoid TreeView "flickering" during an
        ' large node update, it is best to wrap the update code in BeginUpdate...
        ' EndUpdate statements.
        Me.BeginUpdate()

        Dim tn As TreeNode
        ' Add child nodes for each child node in the node clicked by the user.
        ' For performance reasons each node in the DirectoryTreeView
        ' contains only the next level of child nodes in order to display the + sign
        ' to indicate whether the user can expand the node. So when the user expands
        ' a node, in order for the + sign to be appropriately displayed for the next
        ' level of child nodes, *their* child nodes have to be added.
        For Each tn In tvcea.Node.Nodes
            AddDirectories(tn)
        Next tn

        Me.EndUpdate()
    End Sub

    ' This subroutine is used to add a child node for every directory under its
    ' parent node, which is passed as an argument. See further comments in the
    ' OnBeforeExpand event handler.
    Sub AddDirectories(ByVal tn As TreeNode)
        tn.Nodes.Clear()

        Dim strPath As String = tn.FullPath
        Dim diDirectory As New DirectoryInfo(strPath)
        Dim adiDirectories() As DirectoryInfo

        Try
            ' Get an array of all sub-directories as DirectoryInfo objects.
            adiDirectories = diDirectory.GetDirectories()
        Catch exp As Exception
            Exit Sub
        End Try '更多.net源代码 来自乐博网

        Dim di As DirectoryInfo
        For Each di In adiDirectories
            ' Create a child node for every sub-directory, passing in the directory
            ' name and the images its node will use.
            Dim tnDir As New TreeNode(di.Name, 1, 2)
            ' Add the new child node to the parent node.
            tn.Nodes.Add(tnDir)

            ' We could now fill up the whole tree by recursively calling
            ' AddDirectories():
            '
            '   AddDirectories(tnDir)
            '
            ' This is way too slow, however. Give it a try!
        Next
    End Sub

    ' This subroutine clears out the existing TreeNode objects and rebuilds the
    ' DirectoryTreeView, showing the logical drives.
    Public Sub RefreshTree()

        ' For performance reasons and to avoid TreeView "flickering" during an
        ' large node update, it is best to wrap the update code in BeginUpdate...
        ' EndUpdate statements.
        BeginUpdate()

        Nodes.Clear()

        ' Make disk drives the root nodes.
        Dim astrDrives As String() = Directory.GetLogicalDrives()

        Dim strDrive As String
        For Each strDrive In astrDrives
            Dim tnDrive As New TreeNode(strDrive, 0, 0)
            Nodes.Add(tnDrive)
            AddDirectories(tnDrive)

            ' Set the C drive as the default selection.
            If strDrive = "C:\" Then
                Me.SelectedNode = tnDrive
            End If
        Next

        EndUpdate()
    End Sub
End Class

  • 上一篇:

  • 下一篇: 没有了
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    类似Windows资源管理器具有拆分窗口的窗体(VB2010实例…
    动态添加控件的实现方法(VB2010实例)
    创建自定义绘制的用户控件(VB2010实例)
    对文本、图像和树视图节点执行的拖放功能(VB2010实例)
    通用对话框处理文件、颜色和字体的方法(VB2010实例)
    演示如何以多种格式复制和检索剪贴板项(VB2010实例)
    语音API 和语音识别功能(VB2010实例)
    设置文本识别的内置识别器(VB2010实例)
    管理计算机电源状态的类(VB2010实例)
    Tablet PC 上可用的文本识别选项(VB2010实例)
    Tablet PC 2005 中对笔势的系统识别(VB2010实例)
    自定义数据控件(VB2010实例)
    Tablet PC 2005 的区分上下文功能(VB2010实例)
    响应数字化仪触笔背面的橡皮擦(VB2010实例)
    WMI编程实例(VB2010实例)
    系统服务管理实例(VB2010实例)

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]