c#自定义文件对话框,根据选择添加其他控件

时间:2018-09-17 12:14:03

标签: c# hook filedialog

我想自定义一个窗口10样式文件对话框(打开),在文件名下方添加其他控件(请参见下图)。如果可以,请根据选择更新其他控件。

Click here to see image

我该怎么做?

-在对话框上添加我的其他控件

-挂钩回调

我尝试像下面的代码一样钩住文件对话框,但是,似乎经典对话框仅可用。

请帮助我解决这个问题。


jdbc:postgresql://postgres:5432/postgres

1 个答案:

答案 0 :(得分:0)

我自己找到了解决方案。 请尝试在Windows7APICodePack中使用CommonOpenFileDialog或CommonSaveFileDialog。 https://www.nuget.org/packages/Windows7APICodePack-Shell/

引荐

使用该软件包非常容易实现。 这是添加控件的示例。

    public static CommonOpenFileDialog OpenFileDialog(string title, List<CommonFileDialogFilter> filters, string initialDirectory = "", bool multiselect = false)
    {
        var openFilerDialog = new CommonOpenFileDialog();
        openFilerDialog.EnsureReadOnly = true;
        openFilerDialog.IsFolderPicker = false;
        openFilerDialog.AllowNonFileSystemItems = false;
        openFilerDialog.Multiselect = multiselect;
        openFilerDialog.Title = title;

        if (filters != null)
        {
            foreach (var filter in filters)
            {
                openFilerDialog.Filters.Add(filter);
            }
        }

        if (!string.IsNullOrEmpty(initialDirectory))
        {
            openFilerDialog.InitialDirectory = initialDirectory; // Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
        }

        return openFilerDialog;
    }

    private void CustomOpenFileDialog_Click(object sender, RoutedEventArgs e)
    {
        var dialog = FileDialog.OpenFileDialog("Custom OpenFileDialog", new List<CommonFileDialogFilter>() { new CommonFileDialogFilter("stl", "*.stl") });
        AddOpenFileDialogCustomControls(dialog);
        var dialogResult = dialog.ShowDialog();
    }

    public static void AddOpenFileDialogCustomControls(CommonFileDialog openDialog)
    {
        // Add a RadioButtonList
        CommonFileDialogRadioButtonList list = new CommonFileDialogRadioButtonList("radioButtonOptions");
        list.Items.Add(new CommonFileDialogRadioButtonListItem("Option A"));
        list.Items.Add(new CommonFileDialogRadioButtonListItem("Option B"));
        list.SelectedIndex = 1;
        openDialog.Controls.Add(list);
    }