private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            this.isMouseDown = false;

            if (this.tempRectangle != null)
            {
                this.drawnShapes.Add(this.tempRectangle);
            }
            this.tempRectangle = null;

            if (this.tempEllipse != null)
            {
                this.drawnShapes.Add(this.tempEllipse);
            }
            this.tempEllipse = null;

            if (this.tempLine != null)
            {
                this.drawnShapes.Add(this.tempLine);
            }
            this.tempLine = null;

            if (this.tempPenPainting != null)
            {
                this.drawnShapes.Add(this.tempPenPainting);
            }
            this.tempPenPainting = null;

            if (this.tempRubber != null)
            {
                this.drawnShapes.Add(this.tempRubber);
            }
            this.tempRubber = null;

            this.startingPoint = Point.Empty;
            this.Invalidate(); // redraw the surface
        }
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.isMouseDown == false)
            {
                return;
            }

            if (this.selectedTool == PaintTools.Line)
            {
                var endingPoint = e.Location;
                this.tempLine = new Line();
                this.tempLine.StartingPoint = this.startingPoint;
                this.tempLine.EndingPoint   = endingPoint;
                this.tempLine.Thickness     = (int)this.mypen.Width;
                this.tempLine.Color         = this.mypen.Color;
            }

            if (this.selectedTool == PaintTools.Rectangle)
            {
                var endingPoint = e.Location;
                int x           = Math.Min(this.startingPoint.X, endingPoint.X);
                int y           = Math.Min(this.startingPoint.Y, endingPoint.Y);
                int width       = Math.Abs(endingPoint.X - this.startingPoint.X);
                int height      = Math.Abs(endingPoint.Y - this.startingPoint.Y);

                this.tempRectangle             = new DrawnRectangleClass();
                this.tempRectangle.MyRectangle = new Rectangle(x, y, width, height);
                this.tempRectangle.Thickness   = (int)this.mypen.Width;
                this.tempRectangle.Color       = this.mypen.Color;
            }

            if (this.selectedTool == PaintTools.Ellipse)
            {
                var endingPoint = e.Location;
                int x           = Math.Min(this.startingPoint.X, endingPoint.X);
                int y           = Math.Min(this.startingPoint.Y, endingPoint.Y);
                int width       = Math.Abs(endingPoint.X - this.startingPoint.X);
                int height      = Math.Abs(endingPoint.Y - this.startingPoint.Y);

                this.tempEllipse           = new DrawnEllipseClass();
                this.tempEllipse.MyEllipse = new Rectangle(x, y, width, height);
                this.tempEllipse.Thickness = (int)this.mypen.Width;
                this.tempEllipse.Color     = this.mypen.Color;
            }


            if (this.selectedTool == PaintTools.Pen)
            {
                if (this.tempPenPainting == null)
                {
                    this.tempPenPainting = new PenPaintingsClass();
                    this.tempPenPainting.PenPoints.Add(this.startingPoint);
                    this.tempPenPainting.Thickness = (int)this.mypen.Width;
                    this.tempPenPainting.Color     = this.mypen.Color;
                }
                this.tempPenPainting.PenPoints.Add(e.Location);
            }

            if (this.selectedTool == PaintTools.Rubber)
            {
                if (this.tempRubber == null)
                {
                    this.tempRubber = new RubberClass();
                    this.tempRubber.RubberPoints.Add(this.startingPoint);
                    this.tempRubber.Thickness = 5;
                    this.tempRubber.Color     = Color.White;
                }
                this.tempRubber.RubberPoints.Add(e.Location);
            }
            this.Invalidate();
        }