How can I make this control (may a kind of FolderBrowser)

会有一股神秘感。 提交于 2019-12-25 03:30:51

问题


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.


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!