一个简单的资源管理器

窗体控件无非就是有treeview和listview,摆放由自己摆放
以下是代码

 1 using  System;
 2 using  System.Collections.Generic;
 3 using  System.ComponentModel;
 4 using  System.Data;
 5 using  System.Drawing;
 6 using  System.Text;
 7 using  System.IO;
 8 using  System.Windows.Forms;
 9
10 namespace  WindowsApplication1
11 {
12    public partial class Form1 : Form
13    {
14        public Form1()
15        {
16            InitializeComponent();
17        }

18
19        string lj = @"G:\";
20        private void Form1_Load(object sender, EventArgs e)
21        {
22            treeView1 .Nodes.Clear ();
23            treeView1.Nodes.Add(lj, Path.GetFileNameWithoutExtension(lj));//添加第一个节点
24            treeView1.Nodes[0].SelectedImageIndex = 1;
25            DGWJJ(lj,treeView1 .Nodes[0]);
26            //treeView1.Nodes[0].Expand();
27            BLWJJ(lj);
28
29        }

30
31
32        private void BLWJJ(string lj)
33        {
34            listView1.Items.Clear();
35            foreach (string zwjj in Directory.GetDirectories(lj))
36            {
37                listView1.Items.Add(zwjj, Path.GetFileNameWithoutExtension(zwjj), 0);
38            }

39            foreach (string zwjj in Directory.GetFiles(lj))
40            {
41                listView1.Items.Add(zwjj, Path.GetFileName(zwjj), 2);
42            }

43
44        }

45
46        private void DGWJJ(string lj, TreeNode node)
47        {
48            foreach (string zlj in Directory.GetDirectories(lj))
49            {
50                
51                    TreeNode t1 = node.Nodes.Add(zlj, Path.GetFileNameWithoutExtension(zlj));
52                    t1.ImageIndex = 0;
53                    t1.SelectedImageIndex = 1;
54                    DGWJJ(zlj, t1);
55               
56            }

57        }

58
59        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
60        {
61            BLWJJ(e.Node.Name);   
62        }

63
64        private void listView1_DoubleClick(object sender, EventArgs e)
65        {
66            string lslj = listView1.SelectedItems[0].Name;
67            BLWJJ(lslj  );
68
69            DG(lslj,treeView1.Nodes[0]  );
70
71
72        }

73
74        private void DG(string lj,TreeNode tn)
75        {
76            foreach (TreeNode tn1 in tn.Nodes)
77            {
78                if (tn1.Name == lj)
79                {
80                   //tn.Expand;
81                   tn1.Expand();
82                    // tn1.ExpandAll();
83                }
             
84
85                DG(lj, tn1);
86            }

87        }

88
89        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
90        {
91
92        }

93    }

94}

转载于:https://www.cnblogs.com/qjlsharp/archive/2008/07/04/1235945.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值