using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
class MyClass : Form
{
public static void Main()
{
Application.Run(new MyClass());
}
public MyClass()
{
TreeView tree = new TreeView();
tree.Parent = this;
tree.Dock = DockStyle.Fill;
TreeNode nodeDriveC = new TreeNode("C:\\");
tree.Nodes.Add(nodeDriveC);
AddDirectories(nodeDriveC);
}
void AddDirectories(TreeNode node)
{
string strPath = node.FullPath;
DirectoryInfo dirinfo = new DirectoryInfo(strPath);
DirectoryInfo[] adirinfo;
adirinfo = dirinfo.GetDirectories();
foreach (DirectoryInfo di in adirinfo)
{
TreeNode nodeDir = new TreeNode(di.Name);
node.Nodes.Add(nodeDir);
AddDirectories(nodeDir);
}
}
}
|