像“美国广播公司的* .pdf”打开文件对话框C#自定义过滤器 [英] OpenFileDialog C# custom filter like 'ABC*.pdf'

查看:220
本文介绍了像“美国广播公司的* .pdf”打开文件对话框C#自定义过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以指定一个像'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.

这篇关于像“美国广播公司的* .pdf”打开文件对话框C#自定义过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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