ITPub博客

首页 > 应用开发 > IT综合 > C# Resource Management (资源管理器)

C# Resource Management (资源管理器)

原创 IT综合 作者:nonamedemo 时间:2007-11-16 23:10:37 0 删除 编辑

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 prjResourceManagement
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{

TreeNode node = e.Node;
Object obj = node.Tag;
DirectoryInfo f = (DirectoryInfo)obj;
showInfoAtListView(f);


}
private void showInfoAtListView(DirectoryInfo di)
{
this.listView1.Items.Clear();
DirectoryInfo[] dis = di.GetDirectories();
FileInfo[] fis = di.GetFiles();
foreach (DirectoryInfo temp in dis)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = temp.Name;
lvi.ImageIndex = 0;
lvi.SubItems.Add("");
lvi.SubItems.Add("文件夹");
lvi.SubItems.Add(temp.LastWriteTime.ToString());
lvi.Tag = temp;
this.listView1.Items.Add(lvi);
}
foreach (FileInfo temp in fis)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = temp.Name;
lvi.SubItems.Add(temp.Length.ToString());
lvi.SubItems.Add(temp.Extension.ToString());
lvi.ImageIndex = 1;
lvi.SubItems.Add(temp.LastWriteTime.ToString());
lvi.Tag = temp;
this.listView1.Items.Add(lvi);
}

}

private void frmMain_Load(object sender, EventArgs e)
{
try
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
DialogResult dr = fbd.ShowDialog();
if (dr == DialogResult.Cancel)
{
Application.Exit();
}
String path = fbd.SelectedPath;
DirectoryInfo di = new DirectoryInfo(path);
TreeNode root = new TreeNode(di.Name);
this.treeView1.Nodes.Add(root);
root.Tag = di;
ShowAllInfo(di, root);

}
catch
{
//不做处理因为有系统文件访问权限被限制
}

}
private void ShowAllInfo(DirectoryInfo di, TreeNode root)
{
DirectoryInfo[] dis = di.GetDirectories();
foreach (DirectoryInfo temp in dis)
{
TreeNode node = new TreeNode(temp.Name);
root.Nodes.Add(node);
node.Tag = di;
ShowAllInfo(temp, node);
}
}

private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.listView1.SelectedItems.Count == 0)
{
return;
}
Object obj = this.listView1.SelectedItems[0].Tag;
try
{
DirectoryInfo di = (DirectoryInfo)obj;
showInfoAtListView(di);

}
catch
{
FileInfo fi = (FileInfo)obj;
System.Diagnostics.Process.Start(fi.FullName);

}
}

}
}

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10395457/viewspace-982868/,如需转载,请注明出处,否则将追究法律责任。

下一篇: C# Code Summary
请登录后发表评论 登录
全部评论
  • 博文量
    31
  • 访问量
    11502