c# - 将过滤器设置为 OpenFileDialog 以允许典型的图像格式?

标签 c# winforms openfiledialog

我有这段代码,如何让它接受所有典型的图像格式? PNG、JPEG、JPG、GIF?

这是我目前所拥有的:

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. :)
    }             
}

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

最佳答案

来自 the docs ,您需要的过滤器语法如下:

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

即用分号分隔多个扩展名——因此,Image Files|*.jpg;*.jpeg;*.png;...

关于c# - 将过滤器设置为 OpenFileDialog 以允许典型的图像格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2069048/

相关文章:

c# - 如何防止Visual Studio提示将项目.NET 4升级到.NET 4.5

c# - 无法在 foreach 中反转 List<T>

c# - AutoFixture Likeness - 只比较匹配的属性

c# - 隐藏()和可见之间的控制差异?

c# - 如何访问组框中的文本框?

c# - 是否有 Jeff Atwood 的 C#/Winforms .Net 3.5+ 的用户友好异常处理(或类似的)?

c# - 将 Int 参数从 C# 发送到存储过程

.net - 在C#.net的OpenFileDialog中更改按钮文本

c# - 在 C# 中处理 OpenFileDialog?

c# - 修改 SQL Server Compact Edition 的默认连接字符串