Ejemplo n.º 1
0
        private void mItemSaveAs_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.Image == null)
                {
                    return;
                }

                SaveFileDialog dialog = new SaveFileDialog();

                if (this.Image.RawFormat.Guid == ImageFormat.Jpeg.Guid)
                {
                    dialog.Filter = "图片文件(*.jpg)|*.jpg";
                }
                else if (this.Image.RawFormat.Guid == ImageFormat.Bmp.Guid)
                {
                    dialog.Filter = "图片文件(*.bmp)|*.bmp";
                }
                else if (this.Image.RawFormat.Guid == ImageFormat.Gif.Guid)
                {
                    dialog.Filter = "图片文件(*.gif)|*.gif";
                }
                else if (this.Image.RawFormat.Guid == ImageFormat.Png.Guid)
                {
                    dialog.Filter = "图片文件(*.png)|*.png";
                }
                else
                {
                    dialog.Filter = "All files(*.*)|*.*)";
                }

                if (String.IsNullOrEmpty(this.ImageFileName))
                {
                    dialog.FileName = "未命名";
                }
                else
                {
                    dialog.FileName = ImageFileName;
                }

                //dialog.DefaultExt = "图片文件 (*.Jpg)|*.Jpg| 图片文件 (*.Bmp)| *.Bmp|All files (*.*)|*.*";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    string filePath = dialog.FileName;
                    Image  img      = this.Image;

                    if (System.IO.File.Exists(filePath))
                    {
                        var result = MessageBoxEx.Question("文件名已存在,是否替换?");
                        if (result == DialogResult.Cancel || result == DialogResult.No)
                        {
                            return;
                        }

                        System.IO.File.Delete(filePath);
                    }

                    using (FileStream fs = File.Open(filePath, FileMode.OpenOrCreate))
                    {
                        fs.Write(this.ImageData, 0, this.ImageData.Length);
                    }
                }
            }
            catch (Exception ex)
            {
                MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex);
            }
            finally
            {
            }
        }
Ejemplo n.º 2
0
 private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     e.Cancel = !MessageBoxEx.Question("确定退出软件吗?", this);
 }