// This method is quite important and detects all mouse clicks - other methods may need
        // to be implemented to detect other kinds of event handling eg keyboard presses.
        private void mouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                // 'if' statements can distinguish different selected menu operations to implement.
                // There may be other (better, more efficient) approaches to event handling,
                // but this approach works.
                if (selectSquareStatus == true)
                {
                    if (clicknumber == 0)
                    {
                        one         = new Point(e.X, e.Y);
                        clicknumber = 1;
                    }
                    else
                    {
                        two                = new Point(e.X, e.Y);
                        clicknumber        = 0;
                        selectSquareStatus = false;

                        Graphics g        = this.CreateGraphics();
                        Pen      blackpen = new Pen(Color.Black);

                        Square aShape = new Square(one, two);
                        aShape.draw(g, blackpen);
                    }
                }
            }
        }
Exemplo n.º 2
0
        // This method is quite important and detects all mouse clicks - other methods may need
        // to be implemented to detect other kinds of event handling eg keyboard presses.
        private void mouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                // 'if' statements can distinguish different selected menu operations to implement.
                // There may be other (better, more efficient) approaches to event handling,
                // but this approach works.
                if (selectSquareStatus == true)
                {
                    if (clicknumber == 0)
                    {
                        one         = new Point(e.X, e.Y);
                        clicknumber = 1;
                    }
                    else
                    {
                        two                = new Point(e.X, e.Y);
                        clicknumber        = 0;
                        selectSquareStatus = false;

                        Graphics g        = this.CreateGraphics();
                        Pen      blackpen = new Pen(Color.Black);

                        Square aSquare = new Square(one, two);
                        aSquare.ShapeType = (int)ShapeTypes.Square;

                        aSquare.draw(g, blackpen);

                        //add the square to the shapes list
                        shapes.Add(aSquare);
                    }
                }

                //If Triangle Selected
                else if (selectTriangleStatus == true)
                {
                    if (clicknumber == 0)
                    {
                        one         = new Point(e.X, e.Y);
                        clicknumber = 1;
                    }
                    else
                    {
                        two                  = new Point(e.X, e.Y);
                        clicknumber          = 0;
                        selectTriangleStatus = false;

                        Graphics g        = this.CreateGraphics();
                        Pen      blackpen = new Pen(Color.Black);

                        Triangle aTriangle = new Triangle(one, two);
                        aTriangle.ShapeType = (int)ShapeTypes.Triangle;
                        aTriangle.draw(g, blackpen);

                        //add the triangle to the shapes list
                        shapes.Add(aTriangle);
                    }
                }
                else if (selectCircleStatus == true)
                {
                    if (clicknumber == 0)
                    {
                        one         = new Point(e.X, e.Y);
                        clicknumber = 1;
                    }
                    else
                    {
                        two                  = new Point(e.X, e.Y);
                        clicknumber          = 0;
                        selectTriangleStatus = false;

                        Graphics g        = this.CreateGraphics();
                        Pen      blackpen = new Pen(Color.Black);

                        Circle aCircle = new Circle(one, two);
                        aCircle.ShapeType = (int)ShapeTypes.Circle;
                        aCircle.draw(g, blackpen);

                        //add the circle to the shapes list
                        shapes.Add(aCircle);
                    }
                }
            }
        }
Exemplo n.º 3
0
        //rotate the shape when it's selected
        private void itemRotation()
        {
            Graphics   g          = this.CreateGraphics();
            SolidBrush redBrush   = new SolidBrush(Color.Red);
            SolidBrush whiteBrush = new SolidBrush(Color.White);
            Pen        blackPen   = new Pen(Color.Black);

            isMove = false;
            int angle = 10;

            for (int i = 0; i < shapes.Count; i++)
            {
                //calculate the angle and redraw in the new position
                int    width  = Math.Abs(shapes[i].keyPt.X - shapes[i].oppPt.X);
                int    height = Math.Abs(shapes[i].keyPt.Y - shapes[i].oppPt.Y);
                PointF center = new PointF(shapes[i].keyPt.X + (shapes[i].oppPt.X / 2.0f), shapes[i].keyPt.Y + (shapes[i].oppPt.Y / 2.0f));
                //rotate the shape depends on it's type
                if (shapes[i].Selected)
                {
                    if (shapes[i].ShapeType == (int)ShapeTypes.Square)
                    {
                        g.TranslateTransform(this.Width / 2, this.Height / 2);
                        g.RotateTransform(angle);
                        g.TranslateTransform(-this.Width / 2, -this.Height / 2);
                        Square aSquare = new Square(new Point(shapes[i].keyPt.X, shapes[i].keyPt.Y), new Point(shapes[i].oppPt.X, shapes[i].oppPt.Y));
                        aSquare.ShapeType = (int)ShapeTypes.Square;
                        g.Clear(Color.White);
                        aSquare.draw(g, blackPen);
                        ((Square)shapes[i]).fillSquare(g, redBrush);
                    }
                    else if (shapes[i].ShapeType == (int)ShapeTypes.Triangle)
                    {
                        g.TranslateTransform(this.Width / 2, this.Height / 2);

                        g.RotateTransform(angle);

                        g.TranslateTransform(-this.Width / 2, -this.Height / 2);

                        Pen blackpen = new Pen(Color.Black);

                        Triangle aTriangle = new Triangle(new Point(shapes[i].keyPt.X, shapes[i].keyPt.Y), new Point(shapes[i].oppPt.X, shapes[i].oppPt.Y));
                        aTriangle.ShapeType = (int)ShapeTypes.Triangle;
                        g.Clear(Color.White);
                        aTriangle.draw(g, blackpen);
                        ((Triangle)shapes[i]).fillTriangle(g, redBrush);
                    }

                    else if (shapes[i].ShapeType == (int)ShapeTypes.Circle)
                    {
                        g.TranslateTransform(this.Width / 2, this.Height / 2);

                        g.RotateTransform(angle);

                        g.TranslateTransform(-this.Width / 2, -this.Height / 2);


                        Circle aCircle = new Circle(new Point(shapes[i].keyPt.X, shapes[i].keyPt.Y), new Point(shapes[i].oppPt.X, shapes[i].oppPt.Y));
                        aCircle.ShapeType = (int)ShapeTypes.Circle;
                        g.Clear(Color.White);
                        aCircle.draw(g, blackPen);
                        ((Circle)shapes[i]).fillCircle(g, redBrush);
                    }
                }
            }
        }