資源簡介
TreeView和ListView控件聯動事例。源代碼事例,TreeView不同事件下觸發并載ICO,動態顯示效果。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.IO;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
namespace?SecureTree
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????//實例化TreeNode類?TreeNode(string?textint?imageIndexint?selectImageIndex)????????????
????????????TreeNode?rootNode?=?new?TreeNode(“我的電腦“
????????????????IconIndexes.MyComputer?IconIndexes.MyComputer);??//載入顯示?選擇顯示
????????????rootNode.Tag?=?“我的電腦“;????????????????????????????//樹節點數據
????????????rootNode.Text?=?“我的電腦“;???????????????????????????//樹節點標簽內容
????????????this.directoryTree.Nodes.Add(rootNode);???????????????//樹中添加根目錄
????????????//顯示MyDocuments(我的文檔)結點
????????????var?myDocuments?=?Environment.GetFolderPath???????????//獲取計算機我的文檔文件夾
????????????????(Environment.SpecialFolder.MyDocuments);
????????????TreeNode?DocNode?=?new?TreeNode(myDocuments);
????????????DocNode.Tag?=?“我的文檔“;????????????????????????????//設置結點名稱
????????????DocNode.Text?=?“我的文檔“;
????????????DocNode.ImageIndex?=?IconIndexes.MyDocuments;?????????//設置獲取結點顯示圖片
????????????DocNode.SelectedImageIndex?=?IconIndexes.MyDocuments;?//設置選擇顯示圖片
????????????rootNode.Nodes.Add(DocNode);??????????????????????????//rootNode目錄下加載節點
????????????DocNode.Nodes.Add(““);
????????????//循環遍歷計算機所有邏輯驅動器名稱(盤符)
????????????foreach?(string?drive?in?Environment.GetLogicalDrives())
????????????{
????????????????//實例化DriveInfo對象?命名空間System.IO
????????????????var?dir?=?new?DriveInfo(drive);
????????????????switch?(dir.DriveType)???????????//判斷驅動器類型
????????????????{
????????????????????case?DriveType.Fixed:????????//僅取固定磁盤盤符?Removable-U盤?
????????????????????????{
????????????????????????????//Split僅獲取盤符字母
????????????????????????????TreeNode?tNode?=?new?TreeNode(dir.Name.Split(‘:‘)[0]);
????????????????????????????tNode.Name?=?dir.Name;
????????????????????????????tNode.Tag?=?tNode.Name;
????????????????????????????tNode.ImageIndex?=?IconIndexes.FixedDrive;?????????//獲取結點顯示圖片
????????????????????????????tNode.SelectedImageIndex?=?IconIndexes.FixedDrive;?//選擇顯示圖片
????????????????????????????directoryTree.Nodes.Add(tNode);????????????????????//加載驅動節點
????????????????????????????tNode.Nodes.Add(““);
????????????????????????}
????????????????????????break;
????????????????}
????????????}
????????????SetListView();
????????}
????????private?void?directoryTree_AfterExpand(object?sender?TreeViewEventArgs?e)
????????{
????????????e.Node.Expand();
????????}
????????private?void?directoryTree_BeforeExpand(object?sender?TreeViewCancelEventArgs?e)
????????{
????????????TreeViewItems.Add(e.Node);
????????}
????????///?
????????///?自定義類TreeViewItems?調用其Add(TreeNode?e)方法加
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????44032??2019-02-15?12:55??SecureTree\.vs\SecureTree\v14\.suo
?????文件????????189??2019-02-15?09:41??SecureTree\SecureTree\App.config
?????文件??????19968??2019-02-15?12:52??SecureTree\SecureTree\bin\Debug\SecureTree.exe
?????文件????????189??2019-02-15?09:41??SecureTree\SecureTree\bin\Debug\SecureTree.exe.config
?????文件??????24064??2019-02-15?12:52??SecureTree\SecureTree\bin\Debug\SecureTree.pdb
?????文件??????22696??2019-02-15?12:55??SecureTree\SecureTree\bin\Debug\SecureTree.vshost.exe
?????文件????????189??2019-02-15?09:41??SecureTree\SecureTree\bin\Debug\SecureTree.vshost.exe.config
?????文件????????490??2018-04-12?07:35??SecureTree\SecureTree\bin\Debug\SecureTree.vshost.exe.manifest
?????文件??????10645??2019-02-15?12:52??SecureTree\SecureTree\Form1.cs
?????文件???????4732??2019-02-15?12:52??SecureTree\SecureTree\Form1.Designer.cs
?????文件??????16818??2019-02-15?12:52??SecureTree\SecureTree\Form1.resx
?????文件????????614??2019-02-15?12:10??SecureTree\SecureTree\IconIndexes.cs
?????文件????????868??2019-02-15?09:41??SecureTree\SecureTree\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????7180??2019-02-15?12:08??SecureTree\SecureTree\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????648??2019-02-15?12:55??SecureTree\SecureTree\obj\Debug\SecureTree.csproj.FileListAbsolute.txt
?????文件???????1012??2019-02-15?12:52??SecureTree\SecureTree\obj\Debug\SecureTree.csproj.GenerateResource.Cache
?????文件??????19968??2019-02-15?12:52??SecureTree\SecureTree\obj\Debug\SecureTree.exe
?????文件???????7304??2019-02-15?12:52??SecureTree\SecureTree\obj\Debug\SecureTree.Form1.resources
?????文件??????24064??2019-02-15?12:52??SecureTree\SecureTree\obj\Debug\SecureTree.pdb
?????文件????????180??2019-02-15?12:52??SecureTree\SecureTree\obj\Debug\SecureTree.Properties.Resources.resources
?????文件??????????0??2019-02-15?09:41??SecureTree\SecureTree\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
?????文件??????????0??2019-02-15?09:41??SecureTree\SecureTree\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
?????文件??????????0??2019-02-15?09:41??SecureTree\SecureTree\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
?????文件????????522??2019-02-15?09:41??SecureTree\SecureTree\Program.cs
?????文件???????1328??2019-02-15?09:41??SecureTree\SecureTree\Properties\AssemblyInfo.cs
?????文件???????2833??2019-02-15?09:41??SecureTree\SecureTree\Properties\Resources.Designer.cs
?????文件???????5612??2019-02-15?09:41??SecureTree\SecureTree\Properties\Resources.resx
?????文件???????1097??2019-02-15?09:41??SecureTree\SecureTree\Properties\Settings.Designer.cs
?????文件????????249??2019-02-15?09:41??SecureTree\SecureTree\Properties\Settings.settings
?????文件???????3960??2019-02-15?12:10??SecureTree\SecureTree\SecureTree.csproj
............此處省略16個文件信息
- 上一篇:機器視覺棋盤格標定板 CAD格式
- 下一篇:四輸入表決器
評論
共有 條評論