C#-如何自定义OpenFileDialog以选择多个文件夹和文件? [英] C# - How to customize OpenFileDialog to select multiple folders and files?

查看:480
本文介绍了C#-如何自定义OpenFileDialog以选择多个文件夹和文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已发布- https://github.com/scottwis/OpenFileOrFolderDialog.

但是,在使用此功能时,我遇到了一个问题.它使用MFC中的 GetOpenFileName 函数和 OPENFILENAME 结构. 并且 OPENFILENAME 具有名为" templateID "的成员. 它是对话框模板的标识符.并且该示例项目具有" res1.rc "文件,并且还具有模板对话框.

但是我不知道如何将该文件附加到我的C#项目中?

或者还有其他完美的解决方案-"如何自定义OpenFileDialog以选择多个文件夹和文件?"?

解决方案

如果使用FileNames属性而不是FileName属性,则会得到每个所选文件的字符串数组,并使用shift键选择多个文件.像这样:

private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog x = new OpenFileDialog();
    x.Multiselect = true;
    x.ShowDialog();
    string[] result = x.FileNames;

    foreach (string y in result)
       MessageBox.Show(y, "Selected Item", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

对于文件和文件夹,您需要使用 WinAPI ,特定的类是此处.. >

I have posted - How to use OpenFileDialog to select a folder?, I couldn't find the correct answer. So, I have changed my question.

I want to customize OpenFileDialog to select multiple folders and files. I tried to find a solution and could see some posts about it.

From the internet, I found the following project - https://github.com/scottwis/OpenFileOrFolderDialog.

However, while using this, I faced one problem. It uses the GetOpenFileName function and OPENFILENAME structure from MFC. And OPENFILENAME has the member named "templateID". It's the identifier for dialog template. And the sample project has the "res1.rc" file and, also have the templated dialog in it.

But I don't know How can I attach this file to my C# project?

Or is there any other perfect solution about - "How to customize OpenFileDialog to select multiple folders and files?"?

解决方案

If you use the FileNames property instead of the FileName property, you get a string array of each file selected, you select multiple files using the shift key. Like so:

private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog x = new OpenFileDialog();
    x.Multiselect = true;
    x.ShowDialog();
    string[] result = x.FileNames;

    foreach (string y in result)
       MessageBox.Show(y, "Selected Item", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

For files and folders you need to use the CommonOpenFileDialog included with the WinAPI, the particular class is here.

这篇关于C#-如何自定义OpenFileDialog以选择多个文件夹和文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆