过滤器设置为一个OpenFileDialog让典型的图像格式? [英] Setting the filter to an OpenFileDialog to allow the typical image formats?

查看:320
本文介绍了过滤器设置为一个OpenFileDialog让典型的图像格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码,我怎么能允许它接受所有典型的图像格式? ?PNG,JPEG,JPG,GIF



下面是我到目前为止有:

 公共无效EncryptFile()
{
打开文件对话框对话框=新的OpenFileDialog();
dialog.Filter =TXT文件(* .txt)| * .TXT |所有文件(*。*)| *。*;
dialog.InitialDirectory = @C:\;
dialog.Title =请选择一个图像文件进行加密。
如果(dialog.ShowDialog()== DialogResult.OK)
{
//加密选定的文件。以后我会做到这一点。 :)
}
}



注意,过滤器设置为.txt文件。 我可以更改为PNG,但其他类型的什么?



太感谢!



编辑:



我看着办吧,你这是怎么做到这一点:

  dialog.Filter =JPEG文件(* .JPEG)| * .JPEG | PNG文件格式(* .png)| *。PNG | JPG文件(* .JPG)| * .JPG | GIF文件( * .gif注意)| * .gif注意; // MSDN:


解决方案

从的的文档,你需要的是如下的过滤器语法:

  Office文件| * .DOC,*。xls的; * PPT 

即在多个扩展名用分号分隔 - 因此,图像文件| * .JPG; *。JPEG; * png格式; ...


I have this code, how can I allow it to accept all typical image formats? PNG, JPEG, JPG, GIF?

Here's what I have so far:

    public void EncryptFile()
    {            
        OpenFileDialog dialog = new OpenFileDialog();
        dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
        dialog.InitialDirectory = @"C:\";
        dialog.Title = "Please select an image file to encrypt.";
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            //Encrypt the selected file. I'll do this later. :)
        }             
    }

Notice that the filter is set to .txt files. I could change to PNG, but what of the other types?

Thanks SO!

Edit:

I figure it out, this is how you do it:

dialog.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif";

解决方案

From the docs, the filter syntax that you need is as follows:

Office Files|*.doc;*.xls;*.ppt

i.e. separate the multiple extensions with a semicolon -- thus, Image Files|*.jpg;*.jpeg;*.png;....

这篇关于过滤器设置为一个OpenFileDialog让典型的图像格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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