首页 c 打造自己的文件浏览器(C builds its own file browser)

c 打造自己的文件浏览器(C builds its own file browser)

举报
开通vip

c 打造自己的文件浏览器(C builds its own file browser)c 打造自己的文件浏览器(C builds its own file browser) c#打造自己的文件浏览器(C# builds its own file browser) This article is contributed by jvdlvcjpyf This article is contributed by febirds Pdf documents may experience poor browsing on the WAP side. It is recommended that you...

c 打造自己的文件浏览器(C  builds its own file browser)
c 打造自己的文件浏览器(C builds its own file browser) c#打造自己的文件浏览器(C# builds its own file browser) This article is contributed by jvdlvcjpyf This article is contributed by febirds Pdf documents may experience poor browsing on the WAP side. It is recommended that you first select TXT, or download the source file to the local view. C# builds its own file browser C# is so powerful that it can easily make its own file browser. Here is a brief overview of the file browser's general implementation process. For the specific use of these controls, see the online help of C#. You need to use several controls: TreeView (directory tree for display (ListView); used to display the list of files and directories; (Splitter) for TreeView and allows the user to adjust the size of the ListView); other such as: MainMenu, ToolBar, StatusBar, ImageList etc. depending on your actual need. First, create a new C# project (Windows application), named MyFileView, and name the window mainForm, and adjust the main window size (Size). Add controls such as MainMenu, ToolBar, StatusBar, ImageList, etc.. Then, add the TreeView control, which is named treeView, and the Dock property is set to Left, and then add the Splitter control, and also set the Dock property to Left. Finally, add the ListView control, named listView, and the Dock property to Fill. As shown in the following figure. The interface is ready, so how can I display folders and files in this interface? This requires us to add code to implement. First, refer to the following namespace: using System; using System.Drawing; using System.Collections; Using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.InteropServices.Runtime; Add the following code in the mainForm_Load event, used to display the directory tree in the treeView control: private void mainForm_Load (object sender, System.EventArgs E) string[] LogicDrives=System.IO.Directory / / get the logical drive (.GetLogicalDrives); TreeNode[] cRoot =new TreeNode[LogicDrives.Length]; for (int i=0; i< LogicDrives.Length; i++) {TreeNode drivesNode=new TreeNode (LogicDrives[i]).Add (treeView.Nodes; (drivesNode); if = "A:\" LogicDrives[i]! LogicDrives[i]! = "B:\") getSubNode (drivesNode, true);}} wherein getSubNode is a method used to obtain sub directory, to create a directory tree node parameter: PathName to create a child node, this node gets the subdirectory parameters under isEnd: marks the end of the end, true. Private, void, getSubNode (TreeNode, PathName, bool, isEnd) { If (isEnd return //exit this!); TreeNode curNode; DirectoryInfo[] subDir; DirectoryInfo curDir=new DirectoryInfo (PathName.FullPath); try (catch{}) {subDir=curDir.GetDirectories}; foreach (DirectoryInfo D in subDir) {curNode= new TreeNode (d.Name); PathName.Nodes.Add (curNode); getSubNode (curNode, false);}} when the mouse click directory on the left side of the node + number, node will start, at this time, should add the following code in the AfterExpand event, in order to obtain this directory and subdirectories nodes: private void treeView_AfterExpand (object sender, System.Windows.Forms.TreeViewEventArgs, e) {try { Foreach (TreeNode, TN, e.Node,.Nodes, in) {if (... Tn.IsExpanded) getSubNode (tn, True)} catch{}} when the mouse click selects the directory node, the right listView control should display the files and directories in this directory. The code is as follows: private, void, treeView_AfterSelect (object Sender, System.Windows.Forms.TreeViewEventArgs E) {listView.Items.Clear (DirectoryInfo); selDir=new DirectoryInfo (e.Node.FullPath); DirectoryInfo[] listDir; FileInfo[] listFile; try listDir=selDir.GetDirectories; listFile=) {(selDir.GetFiles)} (catch{}; foreach (DirectoryInfo D in listDir) ListView.Items.Add (d.Name, 6); foreach (FileInfo D in listFile listView.Items.Add (d.Name));} so far, a simple file browser is made, of course, it is still the primary, and also can't even use it to open a file, it can not display the file and directory icon. No error handling, no safety control...... What it gives you is just a train of thought. 1. This article is contributed by jvdlvcjpyf This article is contributed by febirds Pdf documents may experience poor browsing on the WAP side. It is recommended that you first select TXT, or download the source file to the local view. C# builds its own file browser C# is so powerful that it can easily make its own file browser. Here is a brief overview of the file browser's general implementation process. For the specific use of these controls, see the online help of C#. You need to use several controls: TreeView (directory tree for display (ListView); used to display the list of files and directories; (Splitter) for TreeView and allows the user to adjust the size of the ListView); other such as: MainMenu, ToolBar, StatusBar, ImageList etc. depending on your actual need. First, create a new C# project (Windows application), named MyFileView, and name the window mainForm, and adjust the main window size (Size). Add controls such as MainMenu, ToolBar, StatusBar, ImageList, etc.. Then, add the TreeView control, which is named treeView, and the Dock property is set to Left, and then add the Splitter control, and also set the Dock property to Left. Finally, add the ListView control, named listView, and the Dock property to Fill. As shown in the following figure. The interface is ready, so how can I display folders and files in this interface? This requires us to add code to implement. First, refer to the following namespace: using System; using System.Drawing; using System.Collections; Using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.InteropServices.Runtime; Add the following code in the mainForm_Load event, used to display the directory tree in the treeView control: private void mainForm_Load (object sender, System.EventArgs E) string[] LogicDrives=System.IO.Directory / / get the logical drive (.GetLogicalDrives); TreeNode[] cRoot =new TreeNode[LogicDrives.Length]; for (int i=0; i< LogicDrives.Length; i++) {TreeNode drivesNode=new TreeNode (LogicDrives[i]).Add (treeView.Nodes; (drivesNode); if = "A:\" LogicDrives[i]! LogicDrives[i]! = "B:\") getSubNode (drivesNode, true);}} wherein getSubNode is a method used to obtain sub directory, create a directory in the tree node, Parameter: PathName is the subdirectory that gets, creates a child node under this node, parameter isEnd: the end flag, and true ends. Private, void, getSubNode (TreeNode, PathName, bool, isEnd) { If (isEnd return //exit this!); TreeNode curNode; DirectoryInfo[] subDir; DirectoryInfo curDir=new DirectoryInfo (PathName.FullPath); try (catch{}) {subDir=curDir.GetDirectories}; foreach (DirectoryInfo D in subDir) {curNode= new TreeNode (d.Name); PathName.Nodes.Add (curNode); getSubNode (curNode, false);}} when the mouse click directory on the left side of the node + number, node will start, at this time, should add the following code in the AfterExpand event, in order to obtain this directory and subdirectories nodes: private void treeView_AfterExpand (object sender, System.Windows.Forms.TreeViewEventArgs, e) {try { Foreach (TreeNode TN in e.Node.Nodes) {if (tn.IsExpanded!) getSubNode (TN, true);}}}} catch{; when the mouse click to select the directory node, the listView on the right side of the control should display the directory of files and directories, the code is as follows: private void treeView_AfterSelect (object Sender, System.Windows.Forms.TreeViewEventArgs E) {listView.Items.Clear (DirectoryInfo); selDir=new DirectoryInfo (e.Node.FullPath); DirectoryInfo[] listDir; FileInfo[] listFile; try listDir=selDir.GetDirectories; listFile=) {(selDir.GetFiles)} (catch{}; foreach (DirectoryInfo D in listDir) ListView.Items.Add (d.Name, 6); foreach (FileInfo D in listFile listView.Items.Add (d.Name));} so far, a simple file browser is made, of course, it is still the primary, and also can't even use it to open a file, it can not display the file and directory icon. No error handling, no safety control...... What it gives you is just a train of thought. One
本文档为【c 打造自己的文件浏览器(C builds its own file browser)】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_963767
暂无简介~
格式:doc
大小:27KB
软件:Word
页数:7
分类:生活休闲
上传时间:2018-02-01
浏览量:23