资源管理器

资源管理器主要代码(带图标)

//C#资源管理器源码
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Runtime.InteropServices;

namespace myTree
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
  public class Form1 : System.Windows.Forms.Form
  {
    private System.Windows.Forms.ImageList TreeImageList;
    private System.Windows.Forms.MainMenu mainMenu1;
    private System.Windows.Forms.MenuItem menuItem1;
    private System.Windows.Forms.ListView listView1;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.TreeView treeView1;
    private System.Windows.Forms.Panel panel2;
    private System.Windows.Forms.Panel panel1;
    private System.Windows.Forms.Splitter splitter1;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.ImageList LisrimageList;
    private System.Windows.Forms.ImageList LisrimageList2;
    private System.Windows.Forms.StatusBar statusBar1;
    private System.Windows.Forms.StatusBarPanel statusBarPanel1;
    private System.Windows.Forms.StatusBarPanel statusBarPanel2;
    private System.Windows.Forms.MenuItem menuItem2;
    private System.Windows.Forms.MenuItem menuItem3;
    private System.Windows.Forms.MenuItem menuItem4;
    private System.Windows.Forms.MenuItem menuItem5;
    private System.Windows.Forms.MenuItem menuItem6;
    private System.Windows.Forms.MenuItem menuItem7;
    private System.Windows.Forms.Label label1;
    private System.ComponentModel.IContainer components;

 public Form1()
 {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   Icon ic0=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",15);
   TreeImageList.Images.Add(ic0);
   Icon ic1=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",5);
   TreeImageList.Images.Add(ic1);
   Icon ic2=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",7);
   TreeImageList.Images.Add(ic2);
   Icon ic3=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",11);
   TreeImageList.Images.Add(ic3);

   Icon ic4=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",3);
   TreeImageList.Images.Add(ic4);
   Icon ic5=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",4);
   TreeImageList.Images.Add(ic5);
   Icon ic6=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",101);
   TreeImageList.Images.Add(ic6);

   GetDrive();
 }

 /// <summary>
 /// 清理所有正在使用的资源。
 /// </summary>
 protected override void Dispose( bool disposing )
 {
   if( disposing )
   {
  if (components != null)
  {
    components.Dispose();
  }
   }
   base.Dispose( disposing );
 }

  #region Windows Form Designer generated code
 /// <summary>
 /// 设计器支持所需的方法 - 不要使用代码编辑器修改
 /// 此方法的内容。
 /// </summary>
 private void InitializeComponent()
 {
   this.components = new System.ComponentModel.Container();
   this.TreeImageList = new System.Windows.Forms.ImageList(this.components);
   this.mainMenu1 = new System.Windows.Forms.MainMenu();
   this.menuItem1 = new System.Windows.Forms.MenuItem();
   this.menuItem2 = new System.Windows.Forms.MenuItem();
   this.menuItem3 = new System.Windows.Forms.MenuItem();
   this.menuItem4 = new System.Windows.Forms.MenuItem();
   this.menuItem5 = new System.Windows.Forms.MenuItem();
   this.menuItem6 = new System.Windows.Forms.MenuItem();
   this.menuItem7 = new System.Windows.Forms.MenuItem();
   this.listView1 = new System.Windows.Forms.ListView();
   this.textBox1 = new System.Windows.Forms.TextBox();
   this.treeView1 = new System.Windows.Forms.TreeView();
   this.panel2 = new System.Windows.Forms.Panel();
   this.label1 = new System.Windows.Forms.Label();
   this.button1 = new System.Windows.Forms.Button();
   this.panel1 = new System.Windows.Forms.Panel();
   this.splitter1 = new System.Windows.Forms.Splitter();
   this.LisrimageList = new System.Windows.Forms.ImageList(this.components);
   this.LisrimageList2 = new System.Windows.Forms.ImageList(this.components);
   this.statusBar1 = new System.Windows.Forms.StatusBar();
   this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
   this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
   this.panel2.SuspendLayout();
   this.panel1.SuspendLayout();
   ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
   ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
   this.SuspendLayout();
   //
   // TreeImageList
   //
   this.TreeImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
   this.TreeImageList.ImageSize = new System.Drawing.Size(16, 16);
   this.TreeImageList.TransparentColor = System.Drawing.Color.Transparent;
   //
   // mainMenu1
   //
   this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                     this.menuItem1,
                     this.menuItem2,
                     this.menuItem3,
                     this.menuItem4});
   //
   // menuItem1
   //
   this.menuItem1.Index = 0;
   this.menuItem1.Text = "文件";
   //
   // menuItem2
   //
   this.menuItem2.Index = 1;
   this.menuItem2.Text = "编辑";
   //
   // menuItem3
   //
   this.menuItem3.Index = 2;
   this.menuItem3.Text = "显隐";
   this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
   //
   // menuItem4
   //
   this.menuItem4.Index = 3;
   this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                     this.menuItem5,
                     this.menuItem6,
                     this.menuItem7});
   this.menuItem4.Text = "列表方式";
   //
   // menuItem5
   //
   this.menuItem5.Index = 0;
   this.menuItem5.Text = "大图标";
   this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
   //
   // menuItem6
   //
   this.menuItem6.Index = 1;
   this.menuItem6.Text = "小图标";
   this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
   //
   // menuItem7
   //
   this.menuItem7.Index = 2;
   this.menuItem7.Text = "详细列表";
   this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
   //
   // listView1
   //
   this.listView1.Activation = System.Windows.Forms.ItemActivation.OneClick;
   this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
   this.listView1.Location = new System.Drawing.Point(221, 25);
   this.listView1.Name = "listView1";
   this.listView1.Size = new System.Drawing.Size(491, 381);
   this.listView1.TabIndex = 3;
   this.listView1.View = System.Windows.Forms.View.SmallIcon;
   this.listView1.ItemActivate += new System.EventHandler(this.listView1_ItemActivate);
   //
   // textBox1
   //
   this.textBox1.Dock = System.Windows.Forms.DockStyle.Top;
   this.textBox1.Name = "textBox1";
   this.textBox1.Size = new System.Drawing.Size(712, 25);
   this.textBox1.TabIndex = 5;
   this.textBox1.Text = "";
   //
   // treeView1
   //
   this.treeView1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  | System.Windows.Forms.AnchorStyles.Left)
  | System.Windows.Forms.AnchorStyles.Right);
   this.treeView1.ImageIndex = -1;
   this.treeView1.ItemHeight = 18;
   this.treeView1.Location = new System.Drawing.Point(0, 29);
   this.treeView1.Name = "treeView1";
   this.treeView1.SelectedImageIndex = -1;
   this.treeView1.Size = new System.Drawing.Size(216, 349);
   this.treeView1.TabIndex = 1;
   this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect_1);
   this.treeView1.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeView1_BeforeExpand_1);
   //
   // panel2
   //
   this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
   this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {
                   this.label1,
                   this.button1});
   this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
   this.panel2.Name = "panel2";
   this.panel2.Size = new System.Drawing.Size(216, 28);
   this.panel2.TabIndex = 0;
   //
   // label1
   //
   this.label1.Dock = System.Windows.Forms.DockStyle.Left;
   this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
   this.label1.Name = "label1";
   this.label1.Size = new System.Drawing.Size(56, 24);
   this.label1.TabIndex = 1;
   this.label1.Text = "文件夹";
   this.label1.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
   //
   // button1
   //
   this.button1.Dock = System.Windows.Forms.DockStyle.Right;
   this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
   this.button1.Location = new System.Drawing.Point(188, 0);
   this.button1.Name = "button1";
   this.button1.Size = new System.Drawing.Size(24, 24);
   this.button1.TabIndex = 0;
   this.button1.Text = "X";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // panel1
   //
   this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
                   this.treeView1,
                   this.panel2});
   this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
   this.panel1.Location = new System.Drawing.Point(0, 25);
   this.panel1.Name = "panel1";
   this.panel1.Size = new System.Drawing.Size(216, 381);
   this.panel1.TabIndex = 6;
   //
   // splitter1
   //
   this.splitter1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
   this.splitter1.Location = new System.Drawing.Point(216, 25);
   this.splitter1.Name = "splitter1";
   this.splitter1.Size = new System.Drawing.Size(5, 381);
   this.splitter1.TabIndex = 7;
   this.splitter1.TabStop = false;
   //
   // LisrimageList
   //
   this.LisrimageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
   this.LisrimageList.ImageSize = new System.Drawing.Size(16, 16);
   this.LisrimageList.TransparentColor = System.Drawing.Color.Transparent;
   //
   // LisrimageList2
   //
   this.LisrimageList2.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
   this.LisrimageList2.ImageSize = new System.Drawing.Size(16, 16);
   this.LisrimageList2.TransparentColor = System.Drawing.Color.Transparent;
   //
   // statusBar1
   //
   this.statusBar1.Location = new System.Drawing.Point(0, 406);
   this.statusBar1.Name = "statusBar1";
   this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
                      this.statusBarPanel1,
                      this.statusBarPanel2});
   this.statusBar1.Size = new System.Drawing.Size(712, 22);
   this.statusBar1.TabIndex = 8;
   this.statusBar1.Text = "statusBar1";
   //
   // statusBarPanel1
   //
   this.statusBarPanel1.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
   this.statusBarPanel1.Text = "statusBarPanel1";
   this.statusBarPanel1.Width = 132;
   //
   // statusBarPanel2
   //
   this.statusBarPanel2.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
   this.statusBarPanel2.Text = "statusBarPanel2";
   this.statusBarPanel2.Width = 132;
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
   this.ClientSize = new System.Drawing.Size(712, 428);
   this.Controls.AddRange(new System.Windows.Forms.Control[] {
                  this.listView1,
                  this.splitter1,
                  this.panel1,
                  this.textBox1,
                  this.statusBar1});
   this.Menu = this.mainMenu1;
   this.Name = "Form1";
   this.Text = "我的资源管理器--曲郑生设计--2002.9";
   this.panel2.ResumeLayout(false);
   this.panel1.ResumeLayout(false);
   ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
   ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
   this.ResumeLayout(false);

 }
  #endregion

 /// <summary>
 /// 应用程序的主入口点。
 /// </summary>
 [STAThread]
 static void Main()
 {
   Application.Run(new Form1());
 }

//*************************************************************************************
 [DllImport("Shell32.dll")]
 public static extern int ExtractIcon(IntPtr h,string strx,int ii);

 [DllImport("Shell32.dll")]
 public static extern int SHGetFileInfo(string pszPath,uint dwFileAttributes,ref SHFILEINFO psfi,uint cbFileInfo, uint uFlags);

 public struct SHFILEINFO
 {
   public IntPtr hIcon;
   public int   iIcon;
   public uint dwAttributes;
   public char szDisplayName;
   public char szTypeName;
 }

 string strFilePath="";
//************************************************************************************* 

 protected virtual Icon myExtractIcon(string FileName,int iIndex)
 {
   try
   {
  IntPtr hIcon=(IntPtr)ExtractIcon(this.Handle,FileName,iIndex);
  if(! hIcon.Equals(null))
  {
    Icon icon=Icon.FromHandle(hIcon);
    return icon;
  }
   }
   catch(Exception ex)
   { MessageBox.Show(ex.Message,"错误提示",0,MessageBoxIcon.Error);}
   return null;
 }
//*************************************************************************************

 protected virtual void SetIcon(ImageList imageList,string FileName,bool tf)
 {
   SHFILEINFO fi=new SHFILEINFO();
   if(tf==true)
   {
  int iTotal=(int)SHGetFileInfo(FileName,0,ref fi,100,  16640);//SHGFI_ICON|SHGFI_SMALLICON
  try
  {
    if(iTotal >0)
    {
   Icon ic=Icon.FromHandle(fi.hIcon);
   imageList.Images.Add(ic);
   //return ic;
    }
  }
  catch(Exception ex)
  { MessageBox.Show(ex.Message,"错误提示",0,MessageBoxIcon.Error);}
   }
   else
   {
  int iTotal=(int)SHGetFileInfo(FileName,0,ref fi,100,  257);
  try
  {
    if(iTotal >0)
    {
   Icon ic=Icon.FromHandle(fi.hIcon);
   imageList.Images.Add(ic);
   //return ic;
    }
  }
  catch(Exception ex)
  { MessageBox.Show(ex.Message,"错误提示",0,MessageBoxIcon.Error);}
   }
   // return null;
 }
//*************************************************************************************

 public void GetDrive()
 {
   treeView1.ImageList=TreeImageList;

   treeView1.BeginUpdate();
   treeView1.Nodes.Clear();

   TreeNode RootNode=new TreeNode("我的电脑",0,0);
   treeView1.Nodes.Add(RootNode);

   int iImageIndex=2;  int iSelectedIndex=2;
   string[] astrDrives = Directory.GetLogicalDrives();

   foreach (string str in astrDrives)
   {
  if(str == "A:\\")
  { iImageIndex=1;  iSelectedIndex=1;}
  else if(str == "G:\\")
  { iImageIndex=3;  iSelectedIndex=3;}
  else
  { iImageIndex=2;  iSelectedIndex=2;}

  TreeNode tnDrive = new TreeNode(str, iImageIndex,iSelectedIndex);
  treeView1.Nodes[0].Nodes.Add(tnDrive);
  AddDirectories(tnDrive);

  if(str == "C:\\")
  { treeView1.SelectedNode=tnDrive;}
   }
   treeView1.EndUpdate();
 }
//*************************************************************************************

 void AddDirectories(TreeNode tn)
 {
   tn.Nodes.Clear();

   string strPath=tn.FullPath;
   strPath=strPath.Remove(0,5);

   //获得当前目录
   DirectoryInfo   dirinfo = new DirectoryInfo(strPath);
   DirectoryInfo[] adirinfo;
   try
   {
  adirinfo = dirinfo.GetDirectories();
   }
   catch
   { return;}

      int iImageIndex=4;  int iSelectedIndex=5;
   foreach (DirectoryInfo di in adirinfo)
   {
  if(di.Name=="RECYCLER"||di.Name=="RECYCLED"||di.Name=="Recycled")
  {iImageIndex=6;  iSelectedIndex=6;}
  else
  {iImageIndex=4;  iSelectedIndex=5;}

  TreeNode tnDir = new TreeNode(di.Name, iImageIndex, iSelectedIndex);
  tn.Nodes.Add(tnDir);
   }

/*
   //获得当前目录下的所有文件
   FileInfo[] dirFiles;
   dirFiles=dirinfo.GetFiles();
   int iCount=7;

   foreach (FileInfo fi in dirFiles)
   {
  //得到每个文件的图标
  string str=fi.FullName;
  try
  {
    SetIcon(TreeImageList,str,false);
  }
  catch(Exception ex)
  { MessageBox.Show(ex.Message,"错误提示",0,MessageBoxIcon.Error);}

  TreeNode tnDir = new TreeNode(fi.Name, iCount, iCount);
  tn.Nodes.Add(tnDir);

  iCount++;
   }
*/
 }
//*************************************************************************************
 //在大图标、小图标、详细列表切换时调用
 protected virtual void ListViewAB(int iii)
 {
   if(iii==1)
   {
  LisrimageList2.ImageSize=new Size(32,32);
  listView1.LargeImageList=LisrimageList2;

  if(listView1.View==View.Details||listView1.View==View.SmallIcon)
  {listView1.View=View.LargeIcon;}
   }
   else if(iii==2)
   {
  if(listView1.View==View.Details||listView1.View==View.LargeIcon)
  {listView1.View=View.SmallIcon;}
   }
   else
   {
  if(listView1.View==View.LargeIcon||listView1.View==View.SmallIcon)
  {listView1.View=View.Details;}
   }
 }
//*************************************************************************************
 private void treeView1_BeforeExpand_1(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
 {
   //base.OnBeforeExpand(e);

   treeView1.BeginUpdate();

   foreach (TreeNode tn in e.Node.Nodes)
   { AddDirectories(tn);}

   treeView1.EndUpdate();
 }

//*************************************************************************************

 protected virtual void InitList(TreeNode tn)
 {
   this.statusBarPanel1.Text="正在刷新文件夹,请稍等.....";
   this.Cursor=Cursors.WaitCursor;

   this.LisrimageList2.Images.Clear();
   this.LisrimageList.Images.Clear();
   listView1.SmallImageList=LisrimageList;
   Icon ic0=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",3);
   LisrimageList.Images.Add(ic0);。
   LisrimageList2.Images.Add(ic0);

   listView1.Clear();
   //设置列表框的表头
   listView1.Columns.Add("文件名",160,HorizontalAlignment.Left);
   listView1.Columns.Add("文件大小",120,HorizontalAlignment.Left);
   listView1.Columns.Add("创建时间",120,HorizontalAlignment.Left);
   listView1.Columns.Add("访问时间",200,HorizontalAlignment.Left);

   string strPath=tn.FullPath;
   strPath=strPath.Remove(0,5);
   //获得当前目录下的所有文件
   DirectoryInfo curDir=new DirectoryInfo(strPath);//创建目录对象。
   FileInfo[] dirFiles;
   try
   {
     dirFiles=curDir.GetFiles();
   }
   catch  { return;}

   string []arrSubItem=new string[4];
   //文件的创建时间和访问时间。
   int iCount=0;    int iconIndex=1;//用1,而不用0是要让过0号图标。
   foreach(FileInfo fileInfo in dirFiles)
   {
  string strFileName=fileInfo.Name;           

  //如果不是文件pagefile.sys
  if(! strFileName.Equals("pagefile.sys"))
  {
    arrSubItem[0]=strFileName;
    arrSubItem[1]=fileInfo.Length+" 字节";
    arrSubItem[2]=fileInfo.CreationTime.ToString();
    arrSubItem[3]=fileInfo.LastAccessTime.ToString();
  }
  else
  { arrSubItem[1]="未知大小"; arrSubItem[2]="未知日期"; arrSubItem[3]="未知日期";}

      //得到每个文件的图标
  string str=fileInfo.FullName;
  try
  {
    SetIcon(LisrimageList,str,false);
    SetIcon(LisrimageList2,str,true);
  }
  catch(Exception ex)
  { MessageBox.Show(ex.Message,"错误提示",0,MessageBoxIcon.Error);}

       //插入列表项
  ListViewItem LiItem=new ListViewItem(arrSubItem,iconIndex);
  listView1.Items.Insert(iCount,LiItem);

  iCount++;
  iconIndex++;
   }
   strFilePath=strPath;
   textBox1.Text=strPath;
   this.statusBarPanel1.Text=strPath;
   this.statusBarPanel2.Text="文件数量: " + iCount.ToString()+"个";
   this.Cursor=Cursors.Arrow;

   //以下是向列表框中插入目录,不是文件。获得当前目录下的各个子目录。
   int iItem=0;

   DirectoryInfo Dir=new DirectoryInfo(strPath);
   foreach(DirectoryInfo di in Dir.GetDirectories())
   {
     ListViewItem LiItem=new ListViewItem(di.Name,0);
  listView1.Items.Insert(iItem,LiItem);
  iItem++;
   }

 }
 //*************************************************************************************

 protected virtual void InitList2(string strName)
 {
   this.statusBarPanel1.Text="正在刷新文件夹,请稍等.....";
   this.Cursor=Cursors.WaitCursor;

   this.LisrimageList2.Images.Clear();
   this.LisrimageList.Images.Clear();
   listView1.SmallImageList=LisrimageList;
   Icon ic0=myExtractIcon("%SystemRoot%\\system32\\shell32.dll",3);
   LisrimageList.Images.Add(ic0);
   LisrimageList2.Images.Add(ic0);

   listView1.Clear();
   //设置列表框的表头
   listView1.Columns.Add("文件名",160,HorizontalAlignment.Left);
   listView1.Columns.Add("文件大小",120,HorizontalAlignment.Left);
   listView1.Columns.Add("创建时间",120,HorizontalAlignment.Left);
   listView1.Columns.Add("访问时间",200,HorizontalAlignment.Left);

   //获得当前目录下的所有文件
   DirectoryInfo curDir=new DirectoryInfo(strName);//创建目录对象。
   FileInfo[] dirFiles;
   try
   {
  dirFiles=curDir.GetFiles();
   }
   catch  { return;}

   string []arrSubItem=new string[4];
   //文件的创建时间和访问时间。
   int iCount=0;    int iconIndex=1;//用1,而不用0是要让过0号图标。
   foreach(FileInfo fileInfo in dirFiles)
   {
  string strFileName=fileInfo.Name;           

  //如果不是文件pagefile.sys
  if(! strFileName.Equals("pagefile.sys"))
  {
    arrSubItem[0]=strFileName;
    arrSubItem[1]=fileInfo.Length+" 字节";
    arrSubItem[2]=fileInfo.CreationTime.ToString();
    arrSubItem[3]=fileInfo.LastAccessTime.ToString();
  }
  else
  { arrSubItem[1]="未知大小"; arrSubItem[2]="未知日期"; arrSubItem[3]="未知日期";}

  //得到每个文件的图标
  string str=fileInfo.FullName;
  try
  {
    SetIcon(LisrimageList,str,false);
    SetIcon(LisrimageList2,str,true);
  }
  catch(Exception ex)
  { MessageBox.Show(ex.Message,"错误提示",0,MessageBoxIcon.Error);}

  //插入列表项
  ListViewItem LiItem=new ListViewItem(arrSubItem,iconIndex);
  listView1.Items.Insert(iCount,LiItem);

  iCount++;
  iconIndex++;//必须加在listView1.Items.Insert(iCount,LiItem);
   }
   strFilePath=strName;//把路径赋值于全局变量strFilePath

   textBox1.Text=strName;
   this.statusBarPanel2.Text="文件数量: " + iCount.ToString()+"个";
   this.Cursor=Cursors.Arrow;

   //以下是向列表框中插入目录,不是文件。获得当前目录下的各个子目录。
   int iItem=0;//调用listView1.Items.Insert(iItem,LiItem);时用。不能使用iconIndex。

   DirectoryInfo Dir=new DirectoryInfo(strName);//创建目录对象。
   foreach(DirectoryInfo di in Dir.GetDirectories())
   {
  ListViewItem LiItem=new ListViewItem(di.Name,0);
  listView1.Items.Insert(iItem,LiItem);
  iItem++;
   }

 }
//*************************************************************************************

    private void treeView1_AfterSelect_1(object sender, System.Windows.Forms.TreeViewEventArgs e)
 {
   if(e.Node.Text=="我的电脑")
   { return;}

   InitList(e.Node);
 }
//*************************************************************************************

    private void button1_Click(object sender, System.EventArgs e)
 {
    this.panel1.Hide();
 }
//*************************************************************************************

    private void listView1_ItemActivate(object sender, System.EventArgs e)
 {
   string str=Path.Combine(strFilePath,listView1.FocusedItem.Text);
   try
   {
  if(listView1.FocusedItem.SubItems.Count>1)
  { System.Diagnostics.Process.Start(str); }
  else
  { InitList2(str); }
   }
   catch  { return;}
 }
//*************************************************************************************
 private void menuItem3_Click(object sender, System.EventArgs e)
 {
   this.panel1.Visible=! panel1.Visible;
 }
//*************************************************************************************
    private void menuItem5_Click(object sender, System.EventArgs e)
 {
   ListViewAB(1);
 }
//*************************************************************************************
    private void menuItem6_Click(object sender, System.EventArgs e)
 {
   ListViewAB(2);
 }
//*************************************************************************************
    private void menuItem7_Click(object sender, System.EventArgs e)
 {
   ListViewAB(3);
 }
//*************************************************************************************

  }
}
时间: 2024-10-12 22:32:19

资源管理器的相关文章

Win10重命名文件夹导致资源管理器卡顿的解决办法

我本机使用的是 Win10 1607,不清楚是因为什么原因导致重命名文件夹时资源管理器会被卡死,找了很长时间终于找到了解决办法,现在我把步骤粘出来以便后续遇到相同问题的朋友能及时解决. 其实操作很简单,只需要简单的三步: 1. 打开任意文件夹 2. 点击左上角菜单栏中的"文件"按钮,选择"更改文件夹和搜索选项",如下图所示: 3. 在弹出的文件夹选项窗口中,依次点击"清除文件资源管理器历史记录"后的"清除"按钮和"还

unity 资源管理器设计

资源管理器,顾名思义,就是管理游戏中的所有资源,包括加载资源,回收资源,销毁资源等等.下面这个资源管理器主要提供了对assetbundle异步加载功能,Resources的加载没有放在里面. 一.使用方法 1.在进入游戏前调用Init(),加载一个资源的名称列表 2.调用AsynGetAsset(string name, Action<UnityEngine.Object> callback)方法(异步) 说明,这里的资源列表是从bundle_list列表中解析出来的,并且有一个manifes

文件服务器资源管理器

文件服务器资源管理器就三部分内容,分别是 配额,文件屏蔽管理,存储报告管理. 磁盘配合: 先说配额的应用方式,配额是先建立配额模板,在配额设置里面要应用配额的文件夹或者磁盘然后绑定上要用的配额模板即可,也可以 采取自定义的设置来做 这里要重点说一下 红框里面的问题,好多人容易在这个地方犯错误,1.在路径上创建配额是在这个文件夹一下的路径上(也可以理解为这个文件夹里面的文件总数不能超过配合) 2.在现有子文件夹贺新文件夹中自动创建配合是在这个文件夹一下的路径下所创建的文件夹大小都收这个配额的限制(

Jtree(节点的渲染+资源管理器)(2)

上一次我们建立一个比较简单的资源管理器,这次我们说一下上面的资源管理器的问题,并且得尽量的贴近windows的资源管理器. 这样一个简单的资源管理树就完成了,下面我们说说它的问题: ① 图片和外观和Windows有差距 这个我们可以通过设置L&F和通过前面写的Renderer那样设置新的图片解决,不是大问题. ② 文件夹里文件多时展开会很慢,会导致界面假死 这个我们可以自己写一个缓加载的TreeNode,让它继承于DefaultMutableTreeNode,在它里面定义加载标示,然后使用Swi

10gocm-&gt;session5-&gt;数据库管理实验-&gt;GC资源管理器资源消耗组演示

<GC资源管理器> 官方文档:administrator's Guide->24 Using the Database Resource Manager 使用率:在实际生产环境中使用的比较少 作用:限制数据库资源的使用,CPU  内存  undo表空间  IO  session 场合:当有多个应用使用一个数据库并且资源紧张时可用"资源管理器"调节 实现:可用GC完成也可用EM完成,还可以使用程序包完成 UI方式:简单,快捷,不容易出错 commend方式:设置复杂,命

win7频繁提示资源管理器已停止工作解决办法

今天上班打开电脑,总是弹出windows资源管理器已停止工作,点击下方的[重新启动],又恢复正常,但是不一会出现这个问题,如此反复,差不多一分钟左右出现一次,让人心烦意乱,没法工作! 一开始尝试了网上各种方法,诸如:修改注册表.进入安全模式杀毒.任务管理器 新建explorer.exe 进程.  甚至搞了一次 系统还原,折腾一上午,可是问题依旧,难道就为这重装一次系统???? 突然灵光一闪,想起查看 系统日志,果然找到一个错误日志, 错误应用程序名称: explorer.exe, 版本: 6.1

使用Windows Form 制作一个简易资源管理器

自制一个简易资源管理器----TreeView控件 第一步.新建project,进行基本设置:(Set as StartUp Project:View/Toolbox/TreeView) 第二步.开始添加节点 添加命名空间using System.IO; 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Dra

Windows 7 在资源管理器中显示软件快捷方式

该方法是利用资源管理器中储存网络位置的文件夹实现的, 不需要修改注册表. 效果如图: 操作方法: 在资源管理器中打开路径 "%appdata%\Microsoft\Windows\Network Shortcuts" 你可以往里面扔 快捷方式,可执行程序,甚至是文件夹.

自定义win8资源管理器左侧导航窗格的方法

Win8自定义资源管理器左侧导航窗格: 快捷键Win+R – 输入regedit: 删除“网络”项目 HKEY_CLASSES_ROOTCLSID{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}ShellFolder Attributes 键值 b0040064 修改 b0940064 删除“家庭组”项目 HKEY_CLASSES_ROOTCLSID{B4FB3F98-C1EA-428d-A78A-D1F5659CBA93}ShellFolder Attributes

Oracle资源管理器(二)-- 创建和使用数据库资源计划

(参考 http://blog.csdn.net/mrluoe/article/details/7969436 -- 整理并实践通过) 第1步,创建3个用户 SQL> create user srcb identified by srcb; User created. SQL> create user kso identified by kso; User created. SQL> create user hr identified by hr; User created SQL>