用C#做个资源管理器

C#做的资源管理器

None.gif using  System;
None.gif
using  System.Text;
None.gif
using  System.Drawing;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.IO;
None.gif
using  System.Windows.Forms;
None.gif
using  System.Data;
None.gif
using  System.Xml;
None.gif
using  System.Runtime.InteropServices; 
None.gif
None.gif
namespace  CSharpWinForm
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Form1 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class Form1 : System.Windows.Forms.Form
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private System.Windows.Forms.TreeView treeView1;
InBlock.gif        
private System.Windows.Forms.TextBox textBox1;
InBlock.gif        
private System.Windows.Forms.ListView listView1;
InBlock.gif        
private System.Windows.Forms.ColumnHeader columnHeader1;
InBlock.gif        
private System.Windows.Forms.ColumnHeader columnHeader2;
InBlock.gif        
private System.Windows.Forms.ColumnHeader columnHeader3;
InBlock.gif        
private System.Windows.Forms.ColumnHeader columnHeader4;
InBlock.gif        
private System.Windows.Forms.Splitter splitter1; 
InBlock.gif
InBlock.gif        
private DirectoryInfo folder; // 用于保存目录信息 
InBlock.gif
        private static string driveLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
InBlock.gif        
private System.Windows.Forms.MainMenu mainMenu1;
InBlock.gif        
private System.Windows.Forms.MenuItem menuItem1;
InBlock.gif        
private System.Windows.Forms.MenuItem menuItem2;
InBlock.gif        
private System.Data.Odbc.OdbcConnection odbcConnection1;     // 用于列举驱动器盘符 
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <summary>
InBlock.gif        
/// 必需的设计器变量。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private System.ComponentModel.Container components = null;
InBlock.gif
InBlock.gif        
public Form1()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// Windows 窗体设计器支持所必需的
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif
InBlock.gif            
//
InBlock.gif            
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 清理所有正在使用的资源。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        protected override void Dispose( bool disposing )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if( disposing )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (components != null
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    components.Dispose();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
base.Dispose( disposing );
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.treeView1 = new System.Windows.Forms.TreeView();
InBlock.gif            
this.textBox1 = new System.Windows.Forms.TextBox();
InBlock.gif            
this.listView1 = new System.Windows.Forms.ListView();
InBlock.gif            
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
InBlock.gif            
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
InBlock.gif            
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
InBlock.gif            
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
InBlock.gif            
this.splitter1 = new System.Windows.Forms.Splitter();
InBlock.gif            
this.mainMenu1 = new System.Windows.Forms.MainMenu();
InBlock.gif            
this.menuItem1 = new System.Windows.Forms.MenuItem();
InBlock.gif            
this.menuItem2 = new System.Windows.Forms.MenuItem();
InBlock.gif            
this.odbcConnection1 = new System.Data.Odbc.OdbcConnection();
InBlock.gif            
this.SuspendLayout();
InBlock.gif            
// 
InBlock.gif            
// treeView1
InBlock.gif            
// 
InBlock.gif
            this.treeView1.Dock = System.Windows.Forms.DockStyle.Left;
InBlock.gif            
this.treeView1.ImageIndex = -1;
InBlock.gif            
this.treeView1.Location = new System.Drawing.Point(00);
InBlock.gif            
this.treeView1.Name = "treeView1";
InBlock.gif            
this.treeView1.SelectedImageIndex = -1;
InBlock.gif            
this.treeView1.Size = new System.Drawing.Size(200573);
InBlock.gif            
this.treeView1.TabIndex = 0;
InBlock.gif            
this.treeView1.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeView1_BeforeSelect);
InBlock.gif            
this.treeView1.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeView1_BeforeExpand);
InBlock.gif            
// 
InBlock.gif            
// textBox1
InBlock.gif            
// 
InBlock.gif
            this.textBox1.Dock = System.Windows.Forms.DockStyle.Top;
InBlock.gif            
this.textBox1.Location = new System.Drawing.Point(2000);
InBlock.gif            
this.textBox1.Name = "textBox1";
InBlock.gif            
this.textBox1.Size = new System.Drawing.Size(59221);
InBlock.gif            
this.textBox1.TabIndex = 1;
InBlock.gif            
this.textBox1.Text = "textBox1";
InBlock.gif            
// 
InBlock.gif            
// listView1
InBlock.gif            
// 
ExpandedSubBlockStart.gifContractedSubBlock.gif
            this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] dot.gif{
InBlock.gif                                                                                        
this.columnHeader1,
InBlock.gif                                                                                        
this.columnHeader2,
InBlock.gif                                                                                        
this.columnHeader3,
ExpandedSubBlockEnd.gif                                                                                        
this.columnHeader4}
);
InBlock.gif            
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
InBlock.gif            
this.listView1.Location = new System.Drawing.Point(20021);
InBlock.gif            
this.listView1.Name = "listView1";
InBlock.gif            
this.listView1.Size = new System.Drawing.Size(592552);
InBlock.gif            
this.listView1.TabIndex = 2;
InBlock.gif            
this.listView1.View = System.Windows.Forms.View.Details;
InBlock.gif            
// 
InBlock.gif            
// columnHeader1
InBlock.gif            
// 
InBlock.gif
            this.columnHeader1.Text = "名称";
InBlock.gif            
this.columnHeader1.Width = 120;
InBlock.gif            
// 
InBlock.gif            
// columnHeader2
InBlock.gif            
// 
InBlock.gif
            this.columnHeader2.Text = "大小";
InBlock.gif            
this.columnHeader2.Width = 100;
InBlock.gif            
// 
InBlock.gif            
// columnHeader3
InBlock.gif            
// 
InBlock.gif
            this.columnHeader3.Text = "类型";
InBlock.gif            
this.columnHeader3.Width = 120;
InBlock.gif            
// 
InBlock.gif            
// columnHeader4
InBlock.gif            
// 
InBlock.gif
            this.columnHeader4.Text = "时间";
InBlock.gif            
this.columnHeader4.Width = 140;
InBlock.gif            
// 
InBlock.gif            
// splitter1
InBlock.gif            
// 
InBlock.gif
            this.splitter1.Location = new System.Drawing.Point(20021);
InBlock.gif            
this.splitter1.Name = "splitter1";
InBlock.gif            
this.splitter1.Size = new System.Drawing.Size(3552);
InBlock.gif            
this.splitter1.TabIndex = 3;
InBlock.gif            
this.splitter1.TabStop = false;
InBlock.gif            
// 
InBlock.gif            
// mainMenu1
InBlock.gif            
// 
ExpandedSubBlockStart.gifContractedSubBlock.gif
            this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] dot.gif{
ExpandedSubBlockEnd.gif                                                                                      
this.menuItem1}
);
InBlock.gif            
// 
InBlock.gif            
// menuItem1
InBlock.gif            
// 
InBlock.gif
            this.menuItem1.Index = 0;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] dot.gif{
ExpandedSubBlockEnd.gif                                                                                      
this.menuItem2}
);
InBlock.gif            
this.menuItem1.Text = "文件";
InBlock.gif            
// 
InBlock.gif            
// menuItem2
InBlock.gif            
// 
InBlock.gif
            this.menuItem2.Index = 0;
InBlock.gif            
this.menuItem2.Text = "新建";
InBlock.gif            
// 
InBlock.gif            
// Form1
InBlock.gif            
// 
InBlock.gif
            this.AutoScaleBaseSize = new System.Drawing.Size(614);
InBlock.gif            
this.ClientSize = new System.Drawing.Size(792573);
InBlock.gif            
this.Controls.Add(this.splitter1);
InBlock.gif            
this.Controls.Add(this.listView1);
InBlock.gif            
this.Controls.Add(this.textBox1);
InBlock.gif            
this.Controls.Add(this.treeView1);
InBlock.gif            
this.Menu = this.mainMenu1;
InBlock.gif            
this.Name = "Form1";
InBlock.gif            
this.Text = "Form1";
InBlock.gif            
this.ResumeLayout(false);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 应用程序的主入口点。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        [STAThread]
InBlock.gif        
static void Main() 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Application.Run(
new Form1());
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void fillTree(TreeView tv) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            DirectoryInfo directory; 
InBlock.gif            
string sCurPath = ""// 重新清空 
InBlock.gif
            tv.Nodes.Clear(); 
InBlock.gif
InBlock.gif            
// 将硬盘上的所有的驱动器都列举出来 
InBlock.gif
            foreachchar c in driveLetters ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                sCurPath 
= c + ":\\"
InBlock.gif                
try 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    
// 获得该路径的目录信息 
InBlock.gif
                    directory = new DirectoryInfo(sCurPath); 
InBlock.gif
InBlock.gif                    
// 如果获得的目录信息正确,则将它添加到目录树视中 
InBlock.gif
                    if ( directory.Exists == true ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif
InBlock.gif                        TreeNode newNode 
= new TreeNode(directory.FullName); 
InBlock.gif                        tv.Nodes.Add(newNode); 
// 添加新的节点到根节点 
InBlock.gif
                        getSubDirs(newNode); 
InBlock.gif                        
// 调用getSubDirs()函数,检查该驱动器上的任何存在子目录 
ExpandedSubBlockEnd.gif
                    }
 
ExpandedSubBlockEnd.gif                }
 
InBlock.gif                
catch( Exception doh) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    Console.WriteLine(doh.Message); 
ExpandedSubBlockEnd.gif                }
 
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif        
private void getSubDirs( TreeNode parent ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            DirectoryInfo directory; 
InBlock.gif            
try 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
// 如果还没有检查过这个文件夹,则检查之 
InBlock.gif
                if ( parent.Nodes.Count == 0 ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    directory 
= new DirectoryInfo(parent.FullPath); 
InBlock.gif                    
foreach( DirectoryInfo dir in directory.GetDirectories()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif
InBlock.gif                        
// 新建一个数节点,并添加到目录树视 
InBlock.gif
                        TreeNode newNode = new TreeNode(dir.Name); 
InBlock.gif                        parent.Nodes.Add(newNode); 
ExpandedSubBlockEnd.gif                    }
 
ExpandedSubBlockEnd.gif                }
 
InBlock.gif
InBlock.gif                
foreach(TreeNode node in parent.Nodes) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    
// 如果还没有检查过这个文件夹,则检查 
InBlock.gif
                    if (node.Nodes.Count == 0
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif
InBlock.gif                        directory 
= new DirectoryInfo(node.FullPath); 
InBlock.gif
InBlock.gif                        
// 检查该目录上的任何子目录 
InBlock.gif
                        foreach( DirectoryInfo dir in directory.GetDirectories()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif
InBlock.gif                            
// 新建一个数节点,并添加到目录树视 
InBlock.gif
                            TreeNode newNode = new TreeNode(dir.Name); 
InBlock.gif                            node.Nodes.Add(newNode); 
ExpandedSubBlockEnd.gif                        }
 
ExpandedSubBlockEnd.gif                    }
 
ExpandedSubBlockEnd.gif                }
 
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
catch( Exception doh ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                Console.WriteLine(doh.Message); 
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif        
private void fillListView(ListView lv, string strPath)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DirectoryInfo directory 
= new DirectoryInfo(strPath);
InBlock.gif            lv.Items.Clear();
InBlock.gif            
foreach( DirectoryInfo dir in directory.GetDirectories()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ListViewItem item 
= new ListViewItem(dir.Name);
InBlock.gif                item.SubItems.Add(
string.Empty);
InBlock.gif                item.SubItems.Add(
"文件夹");
InBlock.gif                item.SubItems.Add(
string.Empty);
InBlock.gif                lv.Items.Add(item);
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
foreach(FileInfo file in directory.GetFiles()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ListViewItem item 
= new ListViewItem(file.Name);
InBlock.gif                item.SubItems.Add((file.Length 
/ 1024).ToString() + " KB");
InBlock.gif                item.SubItems.Add(file.Extension 
+ "文件");
InBlock.gif                item.SubItems.Add(file.LastWriteTime.ToString());
InBlock.gif                lv.Items.Add(item);
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private string fixPath( TreeNode node ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
string sRet = ""
InBlock.gif            
try 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                sRet 
= node.FullPath; 
InBlock.gif                
int index = sRet.IndexOf("\\\\"); 
InBlock.gif                
if (index > 1 ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    sRet 
= node.FullPath.Remove(index, 1); 
ExpandedSubBlockEnd.gif                }
 
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
catch( Exception doh ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                Console.WriteLine(doh.Message); 
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
return sRet; 
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void treeView1_BeforeSelect(object sender, System.Windows.Forms.TreeViewCancelEventArgs e) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            getSubDirs(e.Node); 
// 取得选择节点的子文件夹 
InBlock.gif
            textBox1.Text = fixPath(e.Node); // 更新文本框内容 
InBlock.gif
            folder = new DirectoryInfo(e.Node.FullPath); // 获得它的目录信息
InBlock.gif
            fillListView(listView1, fixPath(e.Node));
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif        
private void treeView1_BeforeExpand(object sender, System.Windows.Forms.TreeViewCancelEventArgs e) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            getSubDirs(e.Node); 
// 取得选择节点的子文件夹 
InBlock.gif
            textBox1.Text = fixPath(e.Node); // 更新文本框内容 
InBlock.gif
            folder = new DirectoryInfo(e.Node.FullPath); // 获得它的目录信息 
ExpandedSubBlockEnd.gif
        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/snowdust/archive/2006/01/05/1650730.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值