准备工作需要加入控件,选择与已选中的“Microsoft Windows Common Controls X.X”相关的文件名。对于旧文件,版本号是 5.0,对于新文件,版本号是 6.0。
窗体加入一个按钮,一个Treeview,改名为FileList,一个Imagelist改名为Img,Imagelist的大小我这里设置为16x16,插入一个图标作为文件夹的图标,
窗体中代码好下:
Private Sub Form_Load()
Me.WindowState = 0
End Sub
Private Sub Command1_Click()
Dim loaddd As String
Dim stMap As Object
MsgBox Command1.Caption & "存档路径没有设置", vbInformation, "技术文件及规范"
loaddd = "请选择" & Command1.Caption & "存档路径:"
Set stMap = CreateObject("shell.application").BrowseForFolder(0, loaddd, &H1)
If Not stMap Is Nothing Then
FileLoad = stMap.self.Path & "\"
Else
End If
Set stMap = Nothing
On Error Resume Next
Dir (FileLoad)
If Err.Number = 52 Then
MsgBox "没有权限打开指定路径,请确认一下能否连接到服务器", vbInformation, "很遗憾"
Exit Sub
End If
FileList.Nodes.Clear
InfoFiles FileLoad, "*.*"
End Sub
Private Sub FileList_DblClick()
If FileList.SelectedItem.Children = 0 Then
FilePath = FileLoad & FileList.SelectedItem.FullPath
Call ShellExecute(Form1.hwnd, vbNullString, FilePath, vbNullString, vbNullString, 1)
End If
End Sub
Private Sub FileList_NodeClick(ByVal Node As MSComctlLib.Node)
Dim FilePath As String
If FileLis

该博客介绍了如何在VB6.0中使用TreeView控件和Imagelist来显示指定目录下的所有子目录和文件,并且自动加载相应的系统图标。通过加入Microsoft Windows Common Controls的引用,结合编程代码实现资源管理功能。
最低0.47元/天 解锁文章
1283

被折叠的 条评论
为什么被折叠?



