wpf, C# 实现目录对话框选择
引用:using System.Windows.Forms;
代码:
FolderBrowserDialog fbWnd = new FolderBrowserDialog();
fbWnd.Description = "选择最终目录"; //目录对话框的描述字符串
fbWnd.SelectedPath = "C:"; //自定义从哪个目录下面选择
fbWnd.ShowNewFolderButton = true; //是否显示目录对话框左下角的“新建文件夹”按钮, true:显示, false: 隐藏
string strbtn = fbWnd.ShowDialog().ToString(); //目录选择完之后是点击确认还是点击取消, 确认: OK, 取消: Cancel
if (strbtn.CompareTo("OK") == 0)
{
System.Windows.MessageBox.Show("点击确认: " + fbWnd.SelectedPath);
}
if (strbtn.CompareTo("Cancel") == 0)
{
System.Windows.MessageBox.Show("点击取消: " + fbWnd.SelectedPath);
}
如图: