项目中引入:SYSTEM.DESIGN.DLL
类中引用:using System.Windows.Forms.Design;
using System.Windows.Forms;
fDialog.Style = FolderBrowserStyles.ShowTextBox; 是让确定的上面显示一个输入路径的文本框。
public class FolderDialog : FolderNameEditor
{
FolderNameEditor.FolderBrowser fDialog = new FolderBrowser();
public FolderDialog()
{
}
public DialogResult DisplayDialog()
{
return DisplayDialog("请选择一个文件夹");
}
public DialogResult DisplayDialog(string description)
{
fDialog.Description = description;
fDialog.Style = FolderBrowserStyles.ShowTextBox;
return fDialog.ShowDialog();
}
public string Path
{
get
{
return fDialog.DirectoryPath;
}
}
}
调用:
FolderDialog fdSource = new FolderDialog();
if (fdSource.DisplayDialog() == DialogResult.OK)
{
txtDirSource.Text = fdSource.Path;
}