简单的文件资源管理器(Simple file explorer)_第1页
简单的文件资源管理器(Simple file explorer)_第2页
简单的文件资源管理器(Simple file explorer)_第3页
简单的文件资源管理器(Simple file explorer)_第4页
简单的文件资源管理器(Simple file explorer)_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、简单的文件资源管理器(Simple file explorer)private void label3_click(object sender,EventArgs e)/关闭资源管理器树视图/位图图像= null;/ /声明一个位图对象/如果(openfiledialog1。showdialog() = = DialogResult。OK)/打开文件对话框选择图片/ / =(位图图像)图像。FromFile(openfiledialog1。文件名);/ /把选择的图片强制转换成位图/ / / FileStream FS =新的FILESTREAM(“X: *。ICO,FileMode。创造);

2、/ /创建文件流/ ico图标,图标。FromHandle(图像。gethicon());/ /图标保存(FS);dispose() /图像;/ / FS。();this.pnlexplorer.visible = false;this.lvwdirectoryfile.width宽度=本;this.lvwdirectoryfile.left = 0;private void toolstripsplitbutton1_click(object sender,EventArgs e)/打开资源管理器树视图this.pnlexplorer.visible =真;this.lvwdirectory

3、file.width =这宽度this.pnlexplorer.width;this.lvwdirectoryfile.left = this.pnlexplorer.width;private void图标toolstripmenuitem_click(object sender,EventArgs e)this.lvwdirectoryfile.view = View.LargeIcon;private void详细信息toolstripmenuitem_click(object sender,EventArgs e)this.lvwdirectoryfile.view =观。细节;/ /

4、加载盘符private void form1_load(object sender,EventArgs e)尝试字符串司机=环境。getlogicaldrives();/ /获取所有盘符名数组foreach(司机的名字)TreeNode结为新的树节点(名称,2, 2);/创建盘符节点并指定图标节点。标签=名称;/ /保存盘符路径到节点的标签tvwdirs。节点添加(节点);DirectoryInfo DirectoryInfo =新DirectoryInfo(名);/ /用指定的路径创建一个目录对象DirectoryInfo dirinfos = DirectoryInfo。getdirect

5、ories();/ /获取该目录下的所有子目录的数组foreach(DirectoryInfo信息dirinfos)/遍历所有子目录树节点infonode =新的树节点(,1, 0);/添加子目录到节点并指定图标infonode。标签= info.fullname;/ /绑定子目录的路径到节点的标签节点。节点添加(infonode);catch(例外)/ /节点单击事件private void tvwdirs_afterselect(object sender,TreeViewEventArgs e)this.cbopath.text = e.node.fullpath;/

6、/把选定节点的路径显示到地址栏this.tsslcount.text = e.node。节点。计数。tostring() +“个对象”;/ /把该节点下的子节点个数,也就是所有目录个显示到状态栏这个文本= e.node.text;/ /把选定节点的名字显示到窗体标题栏字符串路径= e.node。标签。tostring();/ /获取选定节点保存在标签值中的该节点路径setlistview(路径);/ /节点展开前事件private void tvwdirs_beforeexpand(object sender,TreeViewCancelEventArgs e)尝试foreach(在e.nod

7、e TreeNode节点。节点)/遍历选定节点下的所有子节点字符串路径=节点。标签。tostring();/ /获取子节点标签中的路径DirectoryInfo DirInfo =新的DirectoryInfo(路径);DirectoryInfo dirinfos = DirInfo。getdirectories();/ /获取该子节点下的所有子子目录foreach(DirectoryInfo DIR dirinfos)TreeNode dirNode =新的树节点(,1, 0);dirnode标签= dir.fullname;节点。节点添加(dirnode);catch(例外

8、)/ /列表视图双击事件private void lvwdirectoryfile_doubleclick(object sender,EventArgs e)尝试/ /获取选定项的完整路径,为地址栏的路径选定项名字符串的文件名= this.cbopath.text +“”+本。lvwdirectoryfile。selecteditems 0 0 。子项的文本;如果(这。lvwdirectoryfile。selecteditems 0 2 。子项的文本!=“文件夹”)/如果选定项的文件类型不是文件夹/ /打开该项过程=新process();process.startinfo.filename

9、=文件名;start()过程;其他的/ /如果是文件夹,获取选定文件夹的路径字符串temppath =这。lvwdirectoryfile selecteditems 0 。子项文本 0 ;this.cbopath.text + =“”“+ temppath;setlistview(这个。cbopath。文本);/ /根据选定项的路径,显示该项的子目录及子文件到ListViewcatch(例外)private void setlistview(字符串路径)/根据指定路径,显示该路径下的所有文件夹及文件到ListView的方法尝试lvwdirectoryfile clear()。项目;Direc

10、toryInfo DirInfo =新的DirectoryInfo(路径);/ /根据指定的路径创建目录对象DirectoryInfo dirinfos = DirInfo。getdirectories();/ /获取该目录对象下的所有子目录的数组FileInfo 文件getfiles();/ /获取该目录下的所有文件DirInfo。foreach(DirectoryInfo DIR dirinfos)/遍历该目录对象下的所有子目录,项目=新ListViewItem(,1);项目的子项目。AddRange(新的字符串 ”、“文件夹”,迪尔。LastWriteTime。tosho

11、rtdatestring() );lvwdirectoryfile。项目添加(项目);foreach(FileInfo文件在文件)/遍历该目录对象下的所有文件,项目=新ListViewItem(文件名,3);int文件长度= 1;/设置文件的大小为1kb如果(file.length 1024)/如果文件字节超过1024个把他换算成KB值文件长度=(Int32)(双)file.length / 1024)+ 0.5);/(int)(双型数值+ 0.5)四舍五入,得到一个整数值/ /子项为文件大小,文件类型即扩展名,修改日期项目的子项目。AddRange(新的字符串 文件长度+“KB”,文件扩展文

12、件。LastWriteTime。toshortdatestring() );lvwdirectoryfile。项目添加(项目);catch(例外)private void toolstripbutton1_click(object sender,EventArgs e)/转到事件字符串路径= this.cbopath.text;setlistview(路径);private void cbopath_keydown(object sender,KeyEventArgs E)如果(能= =钥匙。进入)字符串路径= this.cbopath.text;setlistview(路径);File ex

13、plorer, with TreeView and ListView, ImageList three controls can be achieved.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 partsPublic partial class Form1: FormPu

14、blic Form1 ()InitializeComponent ();Private void Form1_Load (object sender, EventArgs E)String Drivers = System.IO.Directory.GetLogicalDrives ();/ / initialize treeview controls, the default is the driverFor (int i = 0; I Drivers.Length; i+)TreeNode node = new TreeNode ();Node.Text = Driversi;/ / se

15、t to drive IconNode.ImageIndex = 0;TvDirectory.Nodes.Add (node);Private void tvDirectory_BeforeSelect (object sender, TreeViewCancelEventArgs E)/ / if not the top node, closed icon displayTryThe /SelectedNode property is the object that will lose focusIf (tvDirectory.SelectedNode.Parent = = null)TvD

16、irectory.SelectedNode.ImageIndex = 1;CatchPrivate void tvDirectory_AfterSelect (object sender, TreeViewEventArgs E)Try/ / if this node has been searched, no new searchIf (e.Node.Tag.ToString) = (listed)Return;Catch / / read selected nodes all subdirectoriesString dirs = System.IO.Directory.GetDirect

17、ories (e.Node.FullPath);String fileName;For (int i = 0; I dirs.Length; i+)TreeNode node = new TreeNode ();FileName = dirsi.Substring (dirsi.LastIndexOf () + 1);Node.Text = fileName;Set the image is closed / IconNode.ImageIndex = 1;/ / will be the new node is added to the current node, the current no

18、de sub nodeE.Node.Nodes.Add (node);The search for markers / / set node has searchE.Node.Tag = listed;/ / if not the top node, will be set to open the folder IconIf (e.Node.Parent = = null)E.Node.SelectedImageIndex = 2;/ / remove old file listLvfile.Items.Clear ();/ / the current node corresponding t

19、o retrieval of files in a directoryString files = System.IO.Directory.GetFiles (e.Node.FullPath);For (int i = 0; I files.Length; i+)/ / create a new list item.ListViewItem item = new ListViewItem ();/ / get file nameItem.Text = filesi.Substring (filesi.LastIndexOf () + 1);Item.ForeColor = Color.Red;

20、Item.BackColor = Color.Blue;/ / file.creation.timeItem.SubItems.Add (System.IO.File.GetCreationTime (filesi).ToString ();/ / get the file last access timeItem.SubItems.添加(系统IO文件。getlastaccesstime(文件我)。tostring());item.imageindex = 0;/ /加入到列表中lvfile。项目添加(项目);private void toolstripmenuitem1_click(obje

21、ct sender,EventArgs e)lvfile观= View.LargeIcon;/ /设置菜单选中状态为(int i = 0;i contextmenustrip1.items.count;i+)toolstripmenuitem1。检查= false;toolstripmenuitem2。检查= false;toolstripmenuitem3。检查= false;toolstripmenuitem4。检查= false;toolstripmenuitem1检查=真;private void toolstripmenuitem2_click(object sender,EventArgs e)lvfile观= View.SmallIcon;/ /设置菜单选中状态为(int i = 0;i contextmenustrip1.items.count;i+)toolstripmenuitem1。检查= false;toolstripmenuitem2。检查= false;toolstripmenuitem3。检查= false;toolstripmenuitem4。检查= false;toolstripmenuitem2检查=真;private void toolstripmenuit

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论