简单的文件资源管理器Simple file explorerWord文件下载.docx
- 文档编号:14403885
- 上传时间:2022-10-22
- 格式:DOCX
- 页数:12
- 大小:17.38KB
简单的文件资源管理器Simple file explorerWord文件下载.docx
《简单的文件资源管理器Simple file explorerWord文件下载.docx》由会员分享,可在线阅读,更多相关《简单的文件资源管理器Simple file explorerWord文件下载.docx(12页珍藏版)》请在冰豆网上搜索。
ICO,FileMode。
创造);
//创建文件流
//ico图标,图标。
FromHandle(图像。
gethicon());
//图标保存(FS);
dispose()/图像;
//FS。
();
this.pnlexplorer.visible=false;
this.lvwdirectoryfile.width宽度=本;
this.lvwdirectoryfile.left=0;
}
privatevoidtoolstripsplitbutton1_click(objectsender,EventArgse)/打开资源管理器树视图
this.pnlexplorer.visible=真;
this.lvwdirectoryfile.width=这宽度this.pnlexplorer.width;
this.lvwdirectoryfile.left=this.pnlexplorer.width;
privatevoid图标toolstripmenuitem_click(objectsender,EventArgse)
this.lvwdirectoryfile.view=View.LargeIcon;
privatevoid详细信息toolstripmenuitem_click(objectsender,EventArgse)
this.lvwdirectoryfile.view=观。
细节;
//加载盘符
privatevoidform1_load(objectsender,EventArgse)
尝试
字符串[]司机=环境。
getlogicaldrives();
//获取所有盘符名数组
foreach(司机的名字)
TreeNode结为新的树节点(名称,2,2);
//创建盘符节点并指定图标
节点。
标签=名称;
//保存盘符路径到节点的标签
tvwdirs。
节点添加(节点);
DirectoryInfoDirectoryInfo=新DirectoryInfo(名);
//用指定的路径创建一个目录对象
DirectoryInfo[]dirinfos=DirectoryInfo。
getdirectories();
//获取该目录下的所有子目录的数组
foreach(DirectoryInfo信息dirinfos)/遍历所有子目录
树节点infonode=新的树节点(info.name,1,0);
//添加子目录到节点并指定图标
infonode。
标签=info.fullname;
//绑定子目录的路径到节点的标签
节点添加(infonode);
catch(例外)
//节点单击事件
privatevoidtvwdirs_afterselect(objectsender,TreeViewEventArgse)
this.cbopath.text=e.node.fullpath;
//把选定节点的路径显示到地址栏
this.tsslcount.text=e.node。
计数。
tostring()+“个对象”;
//把该节点下的子节点个数,也就是所有目录个显示到状态栏
这个文本=e.node.text;
//把选定节点的名字显示到窗体标题栏
字符串路径=e.node。
标签。
tostring();
//获取选定节点保存在标签值中的该节点路径
setlistview(路径);
//节点展开前事件
privatevoidtvwdirs_beforeexpand(objectsender,TreeViewCancelEventArgse)
foreach(在e.nodeTreeNode节点。
节点)/遍历选定节点下的所有子节点
字符串路径=节点。
//获取子节点标签中的路径
DirectoryInfoDirInfo=新的DirectoryInfo(路径);
DirectoryInfo[]dirinfos=DirInfo。
//获取该子节点下的所有子子目录
foreach(DirectoryInfoDIRdirinfos)
TreeNodedirNode=新的树节点(dir.name,1,0);
dirnode标签=dir.fullname;
节点添加(dirnode);
//列表视图双击事件
privatevoidlvwdirectoryfile_doubleclick(objectsender,EventArgse)
//获取选定项的完整路径,为地址栏的路径\\选定项名
字符串的文件名=this.cbopath.text+“\”+本。
lvwdirectoryfile。
selecteditems[0][0]。
子项的文本;
如果(这。
selecteditems[0][2]。
子项的文本!
=“文件夹”)/如果选定项的文件类型不是文件夹
//打开该项
过程=新process();
process.startinfo.filename=文件名;
start()过程;
其他的
//如果是文件夹,获取选定文件夹的路径
字符串temppath=这。
lvwdirectoryfileselecteditems[0]。
子项文本[0];
this.cbopath.text+=“”“+temppath;
setlistview(这个。
cbopath。
文本);
//根据选定项的路径,显示该项的子目录及子文件到ListView
privatevoidsetlistview(字符串路径)/根据指定路径,显示该路径下的所有文件夹及文件到ListView的方法
lvwdirectoryfileclear()。
项目;
//根据指定的路径创建目录对象
//获取该目录对象下的所有子目录的数组
FileInfo[]文件getfiles();
//获取该目录下的所有文件DirInfo。
foreach(DirectoryInfoDIRdirinfos)/遍历该目录对象下的所有子目录
,项目=新ListViewItem(dir.name,1);
项目的子项目。
AddRange(新的字符串[]{”、“文件夹”,迪尔。
LastWriteTime。
toshortdatestring()});
项目添加(项目);
foreach(FileInfo文件在文件)/遍历该目录对象下的所有文件
,项目=新ListViewItem(文件名,3);
int文件长度=1;
//设置文件的大小为1kb
如果(file.length>
1024)/如果文件字节超过1024个把他换算成KB值
文件长度=(Int32)(((双)file.length/1024)+0.5);
//(int)(双型数值+0.5)四舍五入,得到一个整数值
//子项为文件大小,文件类型即扩展名,修改日期
AddRange(新的字符串[]{文件长度+“KB”,文件扩展文件。
privatevoidtoolstripbutton1_click(objectsender,EventArgse)/转到事件
字符串路径=this.cbopath.text;
privatevoidcbopath_keydown(objectsender,KeyEventArgsE)
如果(能==钥匙。
进入)
Fileexplorer,withTreeViewandListView,ImageListthreecontrolscanbeachieved.
UsingSystem;
UsingSystem.Collections.Generic;
UsingSystem.ComponentModel;
UsingSystem.Data;
UsingSystem.Drawing;
UsingSystem.Text;
UsingSystem.Windows.Forms;
UsingSystem.IO;
Namespaceparts
PublicpartialclassForm1:
Form
PublicForm1()
InitializeComponent();
PrivatevoidForm1_Load(objectsender,EventArgsE)
String[]Drivers=System.IO.Directory.GetLogicalDrives();
//initializetreeviewcontrols,thedefaultisthedriver
For(inti=0;
I<
Drivers.Length;
i++)
TreeNodenode=newTreeNode();
Node.Text=Drivers[i];
//settodriveIcon
Node.ImageIndex=0;
TvDirectory.Nodes.Add(node);
PrivatevoidtvDirectory_BeforeSelect(objectsender,TreeViewCancelEventArgsE)
//ifnotthetopnode,closedicondisplay
Try
The//SelectedNodepropertyistheobjectthatwilll
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 简单的文件资源管理器Simple file explorer 简单 文件 资源管理器 Simple