示例#1
0
        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);
            }
        }
示例#2
0
 public Form1()
 {
     InitializeComponent();
     g = PnlDrawBoard.CreateGraphics();
     g.SmoothingMode       = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
     pen                   = new Pen(Color.Black, 1);
     pen.StartCap          = pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
     cmbPencilSize.Enabled = false;
     cmbPaintBrush.Enabled = false;
     undo                  = new Stack <Bitmap>();
     redo                  = new Stack <Bitmap>();
 }
示例#3
0
        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;
            }
        }
示例#4
0
        //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;
        }