当我选择文件名" image.mgm"时,对话框System.Windows.Forms.SaveFileDialog 令人惊讶添加扩展名.BMP并返回" 图像。 mgm.BMP "通过属性FileName。 对于" image.png"
,它不会发生几个样本:
如何修复意外(对我来说)行为?
样本来源可以在github上找到:https://github.com/constructor-igor/TechSugar/tree/master/WinForm/FileSaveDialogIssue/FileSaveDialogIssue
UPD : 附加事实:当我添加键" HKEY_CLASSES_ROOT.mgm"到注册表,"文件对话框"停止添加" .BMP"到.mgm
public Form1()
{
InitializeComponent();
this.saveFileDialog.AddExtension = false;
}
private void btnOpenFile_Click(object sender, EventArgs e)
{
saveFileDialog.Title = @"Save calculated image";
saveFileDialog.FileName = "noname.tiff";
saveFileDialog.Filter = @"My Files(*.BMP;*.MGM;*.PNG)|*.BMP;*.MGM;*.PNG|All files (*.*)|*.*";
if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
{
MessageBox.Show(String.Format("File name {0}", saveFileDialog.FileName));
}
}