• 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();

    }
    }
    }


    }

  • 相关阅读:
    企业云盘安全性如何 怎样部署
    Sentinel 控制台部署
    nginx代理静态页面添加二级目录
    java socket
    IDEA
    golang代码生成器
    es 单节点问题
    代码模板
    错误摘要 HTTP 错误 403.14
    安装.Net Framework 4.6.2无法安装的2种情况
  • 原文地址:https://www.cnblogs.com/wrnsweet/p/6186472.html
Copyright © 2020-2023  润新知