开发者

Multiple types in a SaveFileDialog filter

开发者 https://www.devze.com 2023-02-24 10:49 出处:网络
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

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消