我正在尝试让用户选择一个文件夹,这是我的代码
using (var fbd = new FolderBrowserDialog())
{
fbd.RootFolder = Environment.SpecialFolder.MyComputer;
DialogResult result = fbd.ShowDialog();
if (result == DialogResult.OK)
{
//Code
}
}
但是,看来DialogResult
不包含.OK
的扩展,我环顾了其他一些问题,但是它们似乎都没有用。
尝试了答案:dialogresult.ok在savefiledialog上不起作用,用folderbrowserdialog in wpf中的dialogresult。
我可能错过了很明显的东西...
您需要向using System.Windows.Forms;
添加引用。为此:
在解决方案资源管理器中,右键单击参考节点,然后选择 添加参考。
找到
System.Windows.Forms
,然后选择OK
按钮。
,然后首先将其添加到您的using
指令:
using System.Windows.Forms;
,然后:
using (var fbd = new FolderBrowserDialog())
{
fbd.RootFolder = Environment.SpecialFolder.MyComputer;
DialogResult result = fbd.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
//Code
}
}
MessageBoxResult result = MessageBox.Show("Your Message here", "Your caption", MessageBoxButton.YesNo, MessageBoxImage.Warning <= icon required, MessageBoxResult.No <= default result);
if (result == MessageBoxResult.Yes)
{
return;
}