Beispiel #1
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 #2
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);
                 }
             }
         }
     }
 }