using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Ex8_6
{
public partial class Form1 : Form
{
int nDirLevel = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ListDrives();
}
private void ListDrives()
{
TreeNode tn;
string[] drives = Directory.GetLogicalDrives();
tvDir.BeginUpdate();
for (int i = 0; i < drives.Length; i++)
{
tn = new TreeNode(drives[i], 0, 0);
tvDir.Nodes.Add(tn);
}
tvDir.EndUpdate();
tvDir.SelectedNode = tvDir.Nodes[0];
}
private void tvDir_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
ListDirs(e.Node, txtPath.Text.Trim());
}
private void ListDirs(TreeNode tn, string strDir)
{
if (nDirLevel > 4)
{
nDirLevel = 0;
return;
}
nDirLevel++;
string[] arrDirs;
TreeNode tmpNode;
try
{
arrDirs = Directory.GetDirectories(strDir);
if (arrDirs.Length == 0) return;
for (int i = 0; i < arrDirs.Length; i++)
{
tmpNode = new TreeNode(Path.GetFileName(arrDirs[i]), 1, 2);
ListDirs(tmpNode, arrDirs[i]);
tn.Nodes.Add(tmpNode);
}
}
catch
{
return;
}
}
}
}
我是想寫仿制windows資源管理器的功能,代碼和書上的一樣,但是書上寫到這一步雙擊左邊的盤能打開裡面的文件,為什麼我寫的不顯示,幫我看下!
你的代碼只是遞歸添加,並沒有打開文件的方法,你自己好好瞅瞅