private void saveImage() { if (maze != null) { SaveFileDialog sfd = new SaveFileDialog(); sfd.OverwritePrompt = true; sfd.FileName = string.Format("maze {0}.png", maze.Description); sfd.Title = "Save maze as image"; sfd.Filter = FileFormat.MakeFileDialogeString(FileFormat.Common_Images, true, "All Image Formats"); if (sfd.ShowDialog() == DialogResult.OK) { try { Bitmap b = renderMazeAsImage(); b.Save(sfd.FileName); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }