为了解释我想做什么,我不知道在这里谷歌做什么,所以我在这里尝试:我在我的代码中分别使用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);
}
}发布于 2013-02-04 08:20:03
根据您的用户正在使用的操作系统,这是不同的操作:
File name输入中键入元模板(如D:),就可以执行此元计算机。或者你可以把你的路径放在顶部的框中(需要点击它,从导航视图切换到输入视图)。https://stackoverflow.com/questions/14682702
复制相似问题