Beispiel #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);
        }
Beispiel #2
0
        private void tsbOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.Filter      = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            openDialog.Multiselect = true;
            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                string[] files   = openDialog.FileNames;
                TreeNode parNode = tvMenu.Nodes["RootNode"];
                foreach (string file in files)
                {
                    AddToTree(parNode, file);
                }

                if (PubData.DefaultReadChildDir == true)
                {
                    string   currFile = openDialog.FileName;
                    string   currDir  = DirFile.GetLastDirectory(currFile);
                    string[] dirs     = DirFile.GetDirectories(currDir);
                    foreach (string dir in dirs)
                    {
                        files = DirFile.GetFileNames(dir);
                        foreach (string file in files)
                        {
                            AddToTree(parNode, file);
                        }
                    }
                }

                parNode.ExpandAll();
            }
        }
Beispiel #3
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();
        }
Beispiel #4
0
 private void tvMenu_DragDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         String[] files    = (String[])e.Data.GetData(DataFormats.FileDrop);
         TreeNode RootNode = tvMenu.Nodes["RootNode"];
         foreach (String srcFileName in files)
         {
             if (System.IO.File.Exists(srcFileName))
             {
                 AddToTree(RootNode, srcFileName);
             }
             if (System.IO.Directory.Exists(srcFileName))
             {
                 string[] dfiles = DirFile.GetFileNames(srcFileName);
                 foreach (string file in dfiles)
                 {
                     AddToTree(RootNode, file);
                 }
             }
         }
     }
 }