C# 在 OpenFileDialog 中不显示过滤器扩展

发布于 2024-12-25 18:45:33 字数 220 浏览 0 评论 0原文

我在 OpenFileDialog 的 Filter 属性中有多个扩展。是否可以隐藏扩展名并仅显示描述?

示例:

dialog.Filter = "Image files|*.bmp;*.jpg; many image file extensions here"

我只想在文件类型组合框中显示文本:“图像文件”,因为扩展字符串很长。这可能吗?

I have multiple extensions in the Filter property of OpenFileDialog. Is possible to hide the extensions and show only the description?

Sample:

dialog.Filter = "Image files|*.bmp;*.jpg; many image file extensions here"

I want to show only the text: "Image files" in the file type combo box because the extension string is very long. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

爱你不解释 2025-01-01 18:45:33

dialog.Filter = "Image files (*.bmp)|*.bmp;*.jpg"

将仅在组合框中显示“图像文件 (*.bmp)”,同时仍显示具有所有指定扩展名的文件。

或者您可以

dialog.Filter = "Image files (*.bmp;...)|*.bmp;*.jpg"

指示它查找扩展名为 bmp 和其他一些扩展名的文件。

这可能取决于操作系统。我用 Windows 7 进行了测试。

This

dialog.Filter = "Image files (*.bmp)|*.bmp;*.jpg"

will only display "Image files (*.bmp)" in the combo box while still showing files with all the specified extensions.

Or you could do

dialog.Filter = "Image files (*.bmp;...)|*.bmp;*.jpg"

to indicate that it looks for files with extension bmp and some other extensions.

This might depend on the OS. I tested with Windows 7.

日久见人心 2025-01-01 18:45:33

这应该有效:

    dialog.Filter = "All Supported Audio | *.mp3; *.wma | MP3s | *.mp3 | WMAs | *.wma";
    dialog.AutoUpgradeEnabled = false; //using FileDialog.AutoUpgradeEnabled = false it will display the old XP sytle dialog box, which then displays correctly
    dialog.ShowDialog();

This should work:

    dialog.Filter = "All Supported Audio | *.mp3; *.wma | MP3s | *.mp3 | WMAs | *.wma";
    dialog.AutoUpgradeEnabled = false; //using FileDialog.AutoUpgradeEnabled = false it will display the old XP sytle dialog box, which then displays correctly
    dialog.ShowDialog();
孤者何惧 2025-01-01 18:45:33

它应该完全按照您在问题中所写的那样工作:

dialog.Filter = "Image files|*.bmp;*.jpeg;*.jpg;*.png;*.gif"

It should work exactly as you wrote in your question:

dialog.Filter = "Image files|*.bmp;*.jpeg;*.jpg;*.png;*.gif"
稳稳的幸福 2025-01-01 18:45:33

这很简单,你知道。请参阅以下代码片段。它将完美运行。您可以像这样定义更多文件类型。

OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "JPG Files(*.jpg)|*.jpg|PNG Files(*.png)|*.png|BMP Files(*.bmp)|*.bmp|GIF Files(*.gif)|*.gif|TIFF Files(*.tiff)|*.tiff|All Files(*.*)|*.*";

Filter 属性中有两个部分。 "JPG Files(.jpg)|.jpg" 表示选择文件类型的下拉列表将显示 "JPG Files(*.jpg)" 并且过滤器将针对管道字符的下一部分即 *.jpg

注意: 切勿在 *.jpg 后使用任何空格或任何其他文件类型。如果使用,它无法过滤您想要的文件类型。

It is very simple, you know. See the following code snippet. It will run perfectly. You can define more file-types like this way.

OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "JPG Files(*.jpg)|*.jpg|PNG Files(*.png)|*.png|BMP Files(*.bmp)|*.bmp|GIF Files(*.gif)|*.gif|TIFF Files(*.tiff)|*.tiff|All Files(*.*)|*.*";

There are two parts in the Filter property. "JPG Files(.jpg)|.jpg" means the dropdown for selecting file-types will show "JPG Files(*.jpg)" and the filter will happen against the next part of pipe character i.e. *.jpg.

Note: Never use any space after *.jpg or be it any other file-type. If used, it cannot filter your desired file-type.

.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文