我尝试搜索一个文件夹,当我发现要在textBox1中复制地址时,我有下一个代码,但这不能正常工作,使用此代码我只能找到文件。我的问题是:如何更改代码以创建用于查找文件夹的浏览按钮,以及何时发现在textBox1中复制地址?

private void browse_Click(object sender, EventArgs e)
{
    OpenFileDialog fDialog = new OpenFileDialog();
    fDialog.Title = "Browse";
    fDialog.InitialDirectory = @"C:\LegacyApp\MATLAB\R2008a_64-bit";
    fDialog.Filter = "All files(*.*)|*.*|All files(*.*)|*.*";
    fDialog.FilterIndex = 2;
    fDialog.RestoreDirectory = true;
    if (fDialog.ShowDialog() == DialogResult.OK)
    {
        textBox1.Text = fDialog.FileName;
    }
}

最佳答案

要浏览文件夹,您需要FolderBrowserDialog

private void browse_Click(object sender, EventArgs e)
{
     if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         textBox1.Text = folderBrowserDialog1.SelectedPath;
     }
}

09-17 13:34