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

    }
    }
    }


    }

  • 相关阅读:
    (转)如何搭建一个vue项目
    vue项目设置自动打开浏览器
    vue项目关闭代码校验
    前端面试知识点
    图片瀑布流,so easy!
    详细梳理ajax跨域4种解决方案
    css实现内容不相同的左右两个div等高
    简单了解css3轮廓outline
    vue事件监听机制
    table-layout:fixed
  • 原文地址:https://www.cnblogs.com/wrnsweet/p/6186472.html
Copyright © 2011-2022 走看看