C# 自定义浏览文件夹对话框以显示路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/576741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 08:57:18  来源:igfitidea点击:

Customising the browse for folder dialog to show the path

c#winforms

提问by Sam Saffron

Does anyone know what is the simplest way to customise the System.Windows.Forms.FolderBrowserDialog so a path can be entered using text in a textbox below the tree.

有谁知道自定义 System.Windows.Forms.FolderBrowserDialog 的最简单方法是什么,以便可以使用树下方文本框中的文本输入路径。

I want this so it's easy to select unmapped UNC paths.

我想要这个,所以很容易选择未映射的 UNC 路径。

Looks like this this KBhas some supporting information.

看起来这个 KB有一些支持信息。

采纳答案by Cheeso

Just this weekend I needed this. I looked and looked but could not find it. Resorted to writing it myself, based on that KB article, and some other things. Here ya go. FolderBrowserDialogEx

就在这个周末,我需要这个。我看了又看,但找不到。根据那篇知识库文章和其他一些东西,我自己编写了它。给你。 FolderBrowserDialogEx

Full Source code. Free. MS-Public license.

完整的源代码。自由。MS-公共许可证。

FolderBrowserDialogEx

FolderBrowserDialogEx

Code to use it:

使用它的代码:

     var dlg1 = new Ionic.Utils.FolderBrowserDialogEx();
     dlg1.Description = "Select a folder to extract to:";
     dlg1.ShowNewFolderButton = true;
     dlg1.ShowEditBox = true;
     //dlg1.NewStyle = false;
     dlg1.SelectedPath = txtExtractDirectory.Text;
     dlg1.ShowFullPathInEditBox = true;
     dlg1.RootFolder = System.Environment.SpecialFolder.MyComputer;

     // Show the FolderBrowserDialog.
     DialogResult result = dlg1.ShowDialog();
     if (result == DialogResult.OK)
     {
         txtExtractDirectory.Text = dlg1.SelectedPath;
     }

Capabilities: shows editbox, shows full path in edit box. Can be used to browse printers or computers, as well as files+folders, or just folders.

功能:显示编辑框,在编辑框中显示完整路径。可用于浏览打印机或计算机,以及文件+文件夹,或仅文件夹。

Edit, 2018-05-31:If the Codeplex link above does not work for you, this Git resourcealso exists.

编辑,2018 年 5 月 31 日:如果上面的 Codeplex 链接对您不起作用,则此 Git 资源也存在。

回答by Dror

Try under code project folder browser- this allows customizing the dialog in many ways.

在代码项目文件夹浏览器下尝试- 这允许以多种方式自定义对话框。

Also in social.msdn.microsoft.comthere is a post that suggest creating a form of your own for that and even suggest the code for it.

同样在social.msdn.microsoft.com 中,有一个帖子建议为此创建一个您自己的表单,甚至建议它的代码。