In my SaveFileDialog I have multiple types in the filter, however when viewing the dialog if I choose a filter to view files of that type in the directory I am only able to see files for the first and last filters.
bool save;
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = "*";
dlg.DefaultExt = "bmp";
dlg.ValidateNames = true;
dlg.Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif |JPEG Image (.jpeg)|*.jpeg |Png Image (.png)|*.png |Tiff Image (.tiff)|*.tiff |Wmf Image (.wmf)|*.wmf";
开发者_如何转开发 save = (bool)dlg.ShowDialog();
if (save)
{
SaveImage(dlg.FileName);
}
I can see files of type .bmp and .wmf If I change the order of the filters I can always only see the first and last.
Remove the spaces after the file type:
dlg.Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif|JPEG Image (.jpeg)|*.jpeg|Png Image (.png)|*.png|Tiff Image (.tiff)|*.tiff|Wmf Image (.wmf)|*.wmf";
FilterIndex
... DefaultExt is used just during a save.
An index is 1-based so if you want to choose the 2nd option then:
dlg.FilterIndex = 2;
精彩评论