您的位置:程序门 -> .net技术 -> c#



列出我的电脑下的东西


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


列出我的电脑下的东西[已结贴,结贴人:frankla]
发表于:2007-03-17 13:35:12 楼主
在xp
windows   explorer   ->   my   computer

下面还有   my   pictures   等东西
不知道怎么用程序取来这些东西?
发表于:2007-03-17 13:46:371楼 得分:80
//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);

发表于:2007-03-17 13:46:502楼 得分:0
//  
      //   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());
  }

发表于:2007-03-17 13:47:353楼 得分:0
//*************************************************************************************
  [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);}

发表于:2007-03-17 13:47:534楼 得分:0
//插入列表项        
    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);
  }
//*************************************************************************************

    }
}
发表于:2007-03-17 13:54:545楼 得分:4
代码够长!!
发表于:2007-03-17 17:09:116楼 得分:4
该回复于2007-10-26 14:38:58被管理员删除
发表于:2007-03-17 19:40:217楼 得分:4
崩潰..
发表于:2007-03-17 21:39:218楼 得分:4
看热闹并接分
发表于:2007-03-17 21:50:299楼 得分:4
复制粘贴的真爽啊...


快速检索

最新资讯
热门点击