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

    }
    }
    }


    }

  • 相关阅读:
    结对-贪吃蛇游戏结对编项目设计文档
    java基础语法day04
    java基础语法day03
    轻量化ViewController的几个小技巧
    __weak与__block修饰符的区别
    OC与Swift的主要区别
    copy与retain /深拷贝与浅拷贝
    如何理解MVC设计模式
    iOS常见加密方法
    关于RunLoop
  • 原文地址:https://www.cnblogs.com/wrnsweet/p/6186472.html
Copyright © 2011-2022 走看看