我不知道在这里谷歌什么来解释我想做什么,所以我会在这里尝试:我在我的代码中使用OpenFileDialog和FolderBrowserDialog在我的代码中分别浏览文件和目录。
当对话框打开时,用户只能选择实际浏览文件/目录树。但是,在具有许多目录和子目录的树上,用户还希望可以选择手动隐式写入(或粘贴)希望去的完整路径。
如何在代码中实现它?
以下是使用对话框的两个函数:
使用文件夹浏览器对话框:
    private void buttonAddDirectory_Click(object sender, EventArgs e)
    {
        this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
        folderBrowserDialog.SelectedPath = "C:\\";
        if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
        {
            string selectedPath = folderBrowserDialog.SelectedPath;
            if (!searchForFiles(selectedPath))
            {
                MessageBox.Show("The directory: " + selectedPath + " doesn't contain sequences.", "Error!");
                return;
            }
            testForm.enableNumOfProcesses();
            createNewCommand(runBatchScript, selectedPath, true);
        }
    }
使用 OpenFileDialog:
    private void buttonAddFile_Click(object sender, EventArgs e)
    {
        this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
        openFileDialog.InitialDirectory = "C:\\";
        openFileDialog.Filter = "PMD files (*" + sequenceExtenssion + ")|*" + sequenceExtenssion + "|All files (*.*)|*.*";
        if (openFileDialog.ShowDialog() == DialogResult.OK)
        {
            string selectedFile = openFileDialog.FileName;
            if (Path.GetExtension(selectedFile).CompareTo(sequenceExtenssion) != 0)
            {
                MessageBox.Show("The file: " + selectedFile + " is not a sequence file.", "Error!");
                return;
            }
            createNewCommand(batchRunExe, selectedFile, false);
        }
    }