zoukankan      html  css  js  c++  java
  • TreeNode(包含读出文件里的信息)

    public partial class Tree : Form
    {
    public Tree()
    {
    InitializeComponent();
    }

    private void Tree_Load(object sender, EventArgs e)
    {
    string path = @"d:a";
    TreeNode tr = this.TV.Nodes.Add(Directory.GetDirectoryRoot(path));
    TreeNode node1 = new TreeNode();
    LoadData(path,tr.Nodes);

    }

    private void LoadData(string path, TreeNodeCollection tr)
    {
    string[] strs = Directory.GetDirectories(path);
    foreach(var item in strs)
    {
    Tag = Path.GetFileName(item); // 获取或设置包含有关控件的数据的对象。 返回 一个 System.Object,它包含有关控件的数据。 默认值为 null。
    TreeNode tr1 = tr.Add(item ,Tag.ToString());
    LoadData(item,tr1.Nodes);
    }
    string[] strs2 = Directory.GetFiles(path);
    foreach(var item in strs2)
    {
    if(Path.GetExtension(item)==".txt")
    {
    Tag = Path.GetFileName(item);
    tr.Add(item,Tag.ToString());

    }
    }
    }

    private void TV_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
    {
    if(this.TV.SelectedNode!=null)
    {
    string path = this.TV.SelectedNode.Name.ToString();
    if(path.LastIndexOf(".txt")>0)
    {
    FileStream stream = new FileStream(path,FileMode.Open);
    StreamReader sr = new StreamReader(stream,Encoding.Default);
    this.richTextBox1.Text = sr.ReadToEnd();
    sr.Close();
    stream.Close();

    }
    }
    }


    }

  • 相关阅读:
    php RSA 简单实现
    redis 常用操作命令
    ajax短轮询+php与服务器交互制作简易即时聊天网站
    PHP解决网站大数据大流量与高并发
    Memcache所有方法及参数详解
    apache 与 nginx 详解
    apache 与 nginx的区别
    Redis,Memcache的区别和具体应用场景
    Memcache Redis 与Mogodb优缺点
    MySQL 存储
  • 原文地址:https://www.cnblogs.com/wrnsweet/p/6186472.html
Copyright © 2011-2022 走看看