对话框结果不包含'.OK'的扩展名



我正在尝试让用户选择一个文件夹,这是我的代码

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;添加引用。为此:

  1. 在解决方案资源管理器中,右键单击参考节点,然后选择 添加参考。

  2. 找到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;
}

最新更新