In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the production method of C# file browser". In the daily operation, I believe that many people have doubts about the production method of C# file browser. I have consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the production method of C# file browser?" Next, please follow the editor to study!
Several controls are needed to make a C# file browser:
TreeView (used to display the directory tree)
ListView (used to display a list of files and directories)
Splitter (used to allow users to resize TreeView and ListView)
Others, such as MainMenu,ToolBar,StatusBar,ImageList, etc., depend on your actual needs.
First, create a new C# project (Windows application), name it MyFileView, name the window mainForm, and resize the main window (Size). Add controls such as MainMenu,ToolBar,StatusBar,ImageList.
Then, add the TreeView control, name it the treeView,Dock property and set it to Left, then add the Splitter control, and also set the Dock property to Left. * add a ListView control, name it listView,Dock property and set it to Fill.
The interface is done, so how can folders and files be displayed in this interface? This requires us to add code to achieve this.
The C# file browser first refers to the following namespaces:
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
Add the following code to the mainForm_Load event to display the directory tree in the treeView control:
Private void mainForm_Load (object sender, System.EventArgs e) / / get the logical drive string [] LogicDrives=System.IO .Directory .GetLogicalDrives (); TreeNode [] cRoot = new TreeNode [LogicDrives.Length]; for (int iDrives < LogicDrives.Length; iTunes +) {TreeNode drivesNode=new TreeNode (LogicDrives [I]); treeView.Nodes .add (drivesNode); if (LogicDrives [I]! = "A:\\" & LogicDrives [I]! = "B:\\") getSubNode (drivesNode,true);}}
Creation directory tree of C# file browser
Where getSubNode is a method for obtaining subdirectories to create directory tree nodes. Parameter: PathName is the acquired subdirectory to create child nodes under this node. Parameter isEnd: end flag, 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 {subDir=curDir.GetDirectories ();} catch {} foreach (DirectoryInfo d in subDir) {curNode=new TreeNode (d.Name); PathName.Nodes .add (curNode); getSubNode (curNode,false);}}
When the mouse clicks the + sign to the left of the directory node, the node expands, and the following code should be added to the AfterExpand event to get the subdirectory nodes under this directory:
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 clicks to select the directory node, the listView control on the right should display the files and directories under this directory, 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.nameme 6); foreach (FileInfo d in listFile) listView.Items .Add (d.Name) At this point, the study on "what is the making method of C# file browser" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.