private void newToolStripMenuItem_Click(object sender, EventArgs e) //to create a new option in our file menu { DialogResult dialogResult = MessageBox.Show("Do you want to save changes", "WinFormPaint", MessageBoxButtons.YesNoCancel); if (dialogResult == DialogResult.Yes) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "Images (*.png)|*.png"; saveFileDialog1.FilterIndex = 2; saveFileDialog1.RestoreDirectory = true; Bitmap graphicSurface = new Bitmap(900, 300); Graphics gp = Graphics.FromImage(graphicSurface); Rectangle rect = PnlDrawBoard.RectangleToScreen(PnlDrawBoard.ClientRectangle); gp.CopyFromScreen(rect.Location, Point.Empty, PnlDrawBoard.Size); gp.Dispose(); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { graphicSurface.Save(saveFileDialog1.FileName, ImageFormat.Png); filePath = saveFileDialog1.FileName; } } else if (dialogResult == DialogResult.No) { g.Clear(PnlDrawBoard.BackColor); } }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) //to create a save as option in our menu { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "Images (*.png)|*.png"; saveFileDialog1.FilterIndex = 2; saveFileDialog1.RestoreDirectory = true; Bitmap graphicSurface = new Bitmap(900, 300); Graphics gp = Graphics.FromImage(graphicSurface); Rectangle rect = PnlDrawBoard.RectangleToScreen(PnlDrawBoard.ClientRectangle); gp.CopyFromScreen(rect.Location, Point.Empty, PnlDrawBoard.Size); gp.Dispose(); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { graphicSurface.Save(saveFileDialog1.FileName, ImageFormat.Png); filePath = saveFileDialog1.FileName; } }
//Fired when the mouse pointer is over the pnl_Draw and a mouse button is released. private void PnlDrawBoard_MouseUp(object sender, MouseEventArgs e) { if (drawLine) { xEndValue = e.X; yEndValue = e.Y; DrawALine(); } Bitmap graphicSurface = new Bitmap(900, 300); Graphics gp = Graphics.FromImage(graphicSurface); Rectangle rect = PnlDrawBoard.RectangleToScreen(PnlDrawBoard.ClientRectangle); gp.CopyFromScreen(rect.Location, Point.Empty, PnlDrawBoard.Size); gp.Dispose(); undo.Push(graphicSurface); isEraserClicked = startPaint = false; initX = null; initY = null; xStartValue = yStartValue = xEndValue = yEndValue = 0; }