C#窗体程序,做一个如图简单的资源管理器,越简单越好,不需要什么添加文件夹 100

 我来答
山水阿锐
2015-06-16 · TA获得超过34.3万个赞
知道顶级答主
回答量:23.7万
采纳率:91%
帮助的人:3.2亿
展开全部
用如下代码相应替代,一个简单的资源管理器就有了。
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;
using System.Windows.Forms; using System.IO;

namespace MyExplore {
/// <summary>
/// Description of Form1. /// </summary>
public partial class Form1 : Form {
TreeNode rootnode = new TreeNode(); string str = "";
public Form1() {
InitializeComponent(); rootnode.Text = "";
//获得整个系统磁盘驱动
DriveInfo[] drivers = DriveInfo.GetDrives();
//将盘符名加载到TreeView的顶级节点 foreach (DriveInfo driver in drivers) {
TreeNode treenode = new TreeNode(); treenode.Text = driver.Name; rootnode.Nodes.Add( treenode); }
rootnode.Text = "System";
this.treeView1.Nodes.Add(rootnode);

}

void TreeView1AfterSelect(object sender, TreeViewEventArgs e) {
if( e.Node.Text != "System") { str =
e.Node.FullPath.Replace(@"System",string.Empty).Replace(@"\\",@"\"); this.textBox1.Text = str;
DirectoryInfo directoryInfo = new DirectoryInfo(str); try
{
foreach (DirectoryInfo childDirectoryInfo in directoryInfo.GetDirectories()) {
TreeNode directoryNode = new
TreeNode(childDirectoryInfo.Name.ToString());
directoryNode.Tag = childDirectoryInfo.Name.ToString(); e.Node.Nodes.Add(directoryNode); }
this.treeView1.Refresh(); }
catch ( System.IO.DirectoryNotFoundException ee ) {
this.textBox1.Text = ee.ToString(); }
try {
StringBuilder sb = new StringBuilder();
DirectoryInfo directoryInfo1 = new DirectoryInfo(str); foreach (FileInfo fileInfo in directoryInfo1.GetFiles("*.*")) {
sb.AppendLine(fileInfo.Name); }
this.richTextBox1.Text = sb.ToString(); }
catch( System.IO.FileNotFoundException ee ) {
this.textBox1.Text = ee.ToString(); } } } }

}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式