【问题标题】:Folder Dialog return to dialog if criteria not met如果条件不满足,文件夹对话框返回对话框
【发布时间】:2021-11-18 09:12:52
【问题描述】:

为了便于使用,我使用 Ookii Vista 文件夹对话框,并且我正在执行从按钮调用的代码:

using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Ookii.Dialogs;

private string LoadDirectories()
{
    VistaFolderBrowserDialog fbd = new VistaFolderBrowserDialog();
    if (fbd.ShowDialog() == DialogResult.OK && fbd.SelectedPath.Contains("U000"))
    {
        return fbd.SelectedPath;
    }
    else
    {
        MessageBox.Show("Folder must be root assembly, which has U000 in name");
    }
    
    return string.Empty;
}

目前,如果用户没有选择名称中带有 U000 的文件夹,对话框将关闭,但我希望它保持打开状态,直到用户取消或设置正确的文件夹路径。我在任何地方都找不到这个。

【问题讨论】:

    标签: c# visual-studio-2019 folderbrowserdialog ookii


    【解决方案1】:

    简单实现你的需求(加个while):

    使用的 nuget:Ookii.Dialogs.Wpf

    private string LoadDirectories()
    {
        VistaFolderBrowserDialog fbd = new VistaFolderBrowserDialog();
        while (true)
        {
            if (fbd.ShowDialog() == false)
            {
                break;
            }
            else if (fbd.SelectedPath.Contains("U000"))
            {
    
                return fbd.SelectedPath;
            }
            else
            {
                MessageBox.Show("Folder must be root assembly, which has U000 in name");
            }
        }
        return string.Empty;
    }
    

    输出:

    【讨论】:

    • 哇,太简单了,我被它打扰了,谢谢!
    猜你喜欢
    • 2015-05-14
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    • 2016-09-23
    • 2021-06-17
    • 1970-01-01
    • 2011-04-29
    • 2015-11-29
    相关资源
    最近更新 更多