Return to Snippet

Revision: 72016
at April 12, 2017 20:59 by padapara


Initial Code
OpenFileDialog dlg = new OpenFileDialog();
string filter = "Tous les fichiers image|";

ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
string sep = "";

bool isFirst = true;
foreach (var c in codecs)
{
	if (!isFirst)
		sep = ";";

	filter = String.Format("{0}{1}{2}", filter, sep, c.FilenameExtension);
	isFirst = false;
}

filter += "|";

sep = string.Empty;

foreach (var c in codecs)
{
	string codecName = c.CodecName.Substring(8).Replace("Codec", "").Trim();
	filter = String.Format("{0}{1}{2} ({3})|{3}", filter, sep, codecName, c.FilenameExtension);
	sep = "|";
}

dlg.Filter = filter;

Nullable<bool> result = dlg.ShowDialog();

if (result == true)
{
	imageUri = dlg.FileName;
}

Initial URL

                                

Initial Description
This code enable you to have an OpenFileDialog that select directly all types of images.

Initial Title
Code source pour un OpenFileDialog en C# filtrant toutes les extensions image dans un seul groupe... ou pas !

Initial Tags

                                

Initial Language
C#