Exemplo n.º 1
0
        private void panel2_MouseUp(object sender, MouseEventArgs e)
        {
            switch (drawingMode)
            {
            case DrawMode.Square:
                shapeList.Add(new Shape(new Rectangle(dimensions.Anchor, dimensions.Size), new Pen(Pen, 2), drawingMode));
                break;

            case DrawMode.Circle:
                shapeList.Add(new Shape(new Rectangle(dimensions.Anchor, dimensions.Size), new Pen(Pen, 2), drawingMode));
                break;

            case DrawMode.FillSquare:
                shapeList.Add(new Shape(new Rectangle(dimensions.Anchor, dimensions.Size), new SolidBrush(Fill), drawingMode));
                break;

            case DrawMode.FillCircle:
                shapeList.Add(new Shape(new Rectangle(dimensions.Anchor, dimensions.Size), new SolidBrush(Fill), drawingMode));
                break;

            case DrawMode.Line:
                shapeList.Add(new Shape(dimensions.Anchor, dimensions.end, new Pen(Pen, 2), drawingMode));
                break;
            }

            PaintCanvas.Invalidate();

            anchor = Point.Empty;
            dimensions.Update(anchor, Point.Empty);
            dimensions.UpdateLine(anchor, Point.Empty);
            isDrawingMode = false; //upon mouse release, user cannot draw unless he clicks on canvas again
        }
Exemplo n.º 2
0
 private void undoToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         int n = shapeList.Count - 1;
         History.Add(shapeList[n]);
         shapeList.RemoveAt(n);
         PaintCanvas.Invalidate();
     }
     catch (Exception) { }
 }
Exemplo n.º 3
0
 private void redoToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         int o = History.Count - 1;
         shapeList.Add(History[o]);
         History.RemoveAt(o);
         o--;
         PaintCanvas.Invalidate();
     }
     catch (Exception) { }
 }
Exemplo n.º 4
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e) //for newcanvas, we remove each shape from the list
        {
            List <Shape> valuesToDelete = new List <Shape>();

            foreach (Shape s in shapeList)
            {
                valuesToDelete.Add(s);
            }

            foreach (Shape s in valuesToDelete)
            {
                shapeList.Remove(s);
            }

            PaintCanvas.Invalidate();
        }
Exemplo n.º 5
0
        private void panel2_MouseMove(object sender, MouseEventArgs e)
        {
            // update our delta location
            delta.X = e.X;
            delta.Y = e.Y;

            newPointerX.X = e.X;
            newPointerX.Y = e.Y;
            toolStripStatusLabel1.Text = Math.Abs(delta.X).ToString() + "," + "" + Math.Abs(delta.Y).ToString() + " px";

            if (isDrawingMode)
            {
                Point currentPt = new Point(delta.X - anchor.X, delta.Y - anchor.Y);
                toolStripStatusLabel2.Text = Math.Abs(currentPt.X).ToString() + "," + "" + Math.Abs(currentPt.Y).ToString() + " px";

                if (drawingMode == DrawMode.Brush)
                {
                    int  r = (int)Convert.ToInt32(BrushWidthComboBox.SelectedItem.ToString());
                    Size a = new Size(r, r);
                    shapeList.Add(new Shape(delta, new SolidBrush(BrushColorBox.BackColor), a, drawingMode));
                }

                if (drawingMode == DrawMode.Pen)
                {
                    shapeList.Add(new Shape(oldPointerX, newPointerX, new Pen(PenColorBox.BackColor, 1), drawingMode));
                    oldPointerX = newPointerX;
                }

                if (drawingMode == DrawMode.Erase)
                {
                    Size a = new Size(25, 25);
                    shapeList.Add(new Shape(delta, new SolidBrush(PaintCanvas.BackColor), a, drawingMode));
                }

                if (drawingMode == DrawMode.Line)
                {
                    dimensions.UpdateLine(anchor, delta);
                }

                dimensions.Update(anchor, delta);
            }
            // redraw the form
            PaintCanvas.Invalidate();
        }
Exemplo n.º 6
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e) //code for opening BMP file
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.DefaultExt = "bmp";
            openFileDialog.Filter     = "Bitmap files|*.bmp";

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                imagePath = openFileDialog.FileName;
                Image imgBitmap = new Bitmap(imagePath);

                drawingMode = DrawMode.Image;
                shapeList.Add(new Shape(imgBitmap, drawingMode));
                this.PaintCanvas.Size = imgBitmap.Size;
            }

            drawingMode = DrawMode.Square;
            PaintCanvas.Invalidate();
        }