带有输入字段的FolderBrowserDialog [重复]

问题描述 投票:8回答:1

这个问题在这里已有答案:

我不知道在这里谷歌是为了解释我想做什么,所以我会在这里尝试:我在我的代码中使用OpenFileDialogFolderBrowserDialog分别浏览文件和目录。

当对话框打开时,用户只能选择实际浏览文件/目录树。但是,在具有许多目录和子目录的树上,用户还希望手动隐式写入(或粘贴)希望去的完整路径。

如何在代码中实现它?

以下是使用对话框的两个函数:

使用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);
        }
    }
c# forms openfiledialog folderbrowserdialog file-browser
1个回答
0
投票

根据您的用户使用此操作系统的操作方式不同:

  1. Windows 7,Vista,XP等 - 您只需在D:输入中键入元命令(如File name),即可执行此metacommand。或者您可以将路径放在顶部的框中(需要单击它以从导航视图切换到输入视图)
  2. 如果您使用的是Mono,而其他一些GUI标准对话框可能根本不提供此功能,那么您必须自己实现这些对话框。
© www.soinside.com 2019 - 2024. All rights reserved.