我不确定如何通过搜索来解释我想做的事情,因此我会在这里尝试:
我在代码中使用
当对话框打开时,用户只能浏览文件/目录树。但是,在具有许多目录和子目录的树上,用户还希望手动显式写入(或粘贴)完整路径。
我该如何在代码中实现它?
以下是使用对话框的两个函数: 使用FolderBrowserDialog:
OpenFileDialog
和FolderBrowserDialog
浏览文件和目录。当对话框打开时,用户只能浏览文件/目录树。但是,在具有许多目录和子目录的树上,用户还希望手动显式写入(或粘贴)完整路径。
我该如何在代码中实现它?
以下是使用对话框的两个函数: 使用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);
}
}
FolderBrowserDialog fbd = new FolderBrowserDialog();
和fbd.ShowDialog();
你可以说你已经做到了,展示这两行代码,并说明你想要一个输入字段。 - barlop