像“美国广播公司的* .pdf”打开文件对话框C#自定义过滤器自定义、美国、过滤器、对话框

2023-09-04 08:52:04 作者:残花败落

是否可以指定一个像'ABC的* .pdf,这意味着自定义过滤器:显示所有的PDF它与ABC开始

Is it possible to specify custom filters like 'ABC*.pdf' which means: "Show all PDF which starts with ABC"?

我只能指定的* .pdf,* doc和的 的,等等。

I can only specify *.pdf, *.doc, ., etc.

谢谢 弗洛里安

推荐答案

更新的

Updated

更改我的解决方案一点,实现了以下效果会更好后。这不是一个完整的硬过滤器,而是利用了文件名属性基本上应该给你你需要什么;

Changed my solution a little, after realizing the following would be better. This is not a complete "hard filter", but making use of the FileName property should basically give you what you need;

using System;
using System.Windows.Forms;

namespace TestingFileOpenDialog
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.openFileDialog1.FileName = "pro*";
            this.openFileDialog1.Filter = "Pdf Files|*.pdf";
            this.openFileDialog1.ShowDialog();
        }
    }
}

我想这可能取决于哪个操作系统您正在使用,但它在我的情况下,任何的方式做工作,在Windows 8上。

I suppose this might depend on which OS you are working with, but it did work in my case any way, on Windows 8.

我也意识到,这并不过滤出所有不相关的文件,永久,但它至少提供了一个初始过滤器。

I also realize that this does not filter out all irrelevant files "permanently", but it does at least provide an initial filter.

结果:

没有 PRO * 文件名中的场,这将显示其他多个PDF文件。

Without pro* in the FileName-field, this will show several other PDF files.