Пример #1
0
        private void AddToTree(TreeNode parNode, string fileName)
        {
            TreeNode RootNode = tvMenu.Nodes["RootNode"];

            if (parNode == null)
            {
                parNode = RootNode;
            }
            TreeNode[] exsCount = parNode.Nodes.Find("trNode" + DirFile.GetFileNameNoExtension(fileName), false);
            if (exsCount.Length > 0)
            {
                return;
            }
            TreeNode childNode = new TreeNode();

            childNode.ImageKey = "Text.ico";
            string strTmp = DirFile.GetFileName(fileName);

            childNode.Text        = strTmp;
            childNode.ToolTipText = fileName;
            strTmp         = DirFile.GetFileNameNoExtension(fileName);
            childNode.Tag  = strTmp;
            childNode.Name = "trNode" + strTmp;
            parNode.Nodes.Add(childNode);
        }
Пример #2
0
        private void SaveToFile(string fileName, TreeNode currNode)
        {
            if (!File.Exists(fileName))
            {
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                saveFileDialog1.Filter           = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
                saveFileDialog1.Title            = "保存数据...";
                saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                saveFileDialog1.RestoreDirectory = true;
                saveFileDialog1.ShowHelp         = true;

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    fileName          = saveFileDialog1.FileName;//dest
                    currNode.ImageKey = "Text.ico";
                    string strTmp = DirFile.GetFileName(fileName);
                    currNode.Text        = strTmp;
                    currNode.ToolTipText = fileName;
                    strTmp        = DirFile.GetFileNameNoExtension(fileName);
                    currNode.Tag  = strTmp;
                    currNode.Name = "trNode" + strTmp;
                }
            }

            StreamWriter sw = new StreamWriter(fileName, false, Encoding.GetEncoding(PubData.DefaulTextEncoding));

            sw.WriteLine(rtxtContent.Text);
            sw.Close();
        }