问题
As you can see in the picture below, this looks like a file dialog and folder browser. This dialog can select only folder(not file). Is this a custom control? If so, then please give me advice on how to make it. This is a Winforms application.
![](https://i0.wp.com/i.stack.imgur.com/6hM4z.jpg)
回答1:
It is the native Vista IFileDialog based version of OpenFileDialog. With the FOS_PICKFOLDERS turned on. That option is not exposed in .NET, it isn't available on earlier versions of Windows. You can get a wrapper for it from the Windows API Code Pack, CommonOpenFileDialog.IsFolderPicker property.
回答2:
use the FolderBrowserDialog:
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "Select a folder";
DialogResult result = dialog.ShowDialog();
String selectedFolder = String.Empty;
if (result == DialogResult.OK)
{
selectedFolder = dialog.SelectedPath;
}
dialog.Dispose();
The FolderBrowserDialog has a different user interface than the Dialog you showed in your screenshot. If it needs to look like that, how about reading this answer?
You should also consider using the third-party Ookii.Dialogs wrapper classes.
来源:https://stackoverflow.com/questions/8629663/how-can-i-make-this-control-may-a-kind-of-folderbrowser