gpt4 book ai didi

c# - 带输入字段的 FolderBrowserDialog

转载 作者:太空狗 更新时间:2023-10-29 19:48:01 26 4
gpt4 key购买 nike

<分区>

我不确定要在这里谷歌什么来解释我想做什么,所以我会在这里尝试:我在代码中同时使用 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);
}
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com