Example #1
0
        private void panel1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (drawShape.getShape() == null)
                {
                    MessageBox.Show("Bạn vui lòng chọn hình trước khi vẽ");
                    return;
                }
                if (!drawShape.getShape().checkDrawable())//if (!endClick)
                {
                    switch (drawShape.getShape().getTypeDraw())
                    {
                    case TypeDraw.Line:
                        Line line = (Line)drawShape.getShape();
                        //line.setStartPoint(new Point(Convert.ToInt16(round(e.X)), Convert.ToInt16(round(e.Y))));
                        line.setStartPoint(new Point(round(e.X), round(e.Y)));
                        break;

                    case TypeDraw.Rectangle:
                        Rectangle rectangle = (Rectangle)drawShape.getShape();
                        rectangle.setStartPoint(new Point(round(e.X), round(e.Y)));
                        break;

                    case TypeDraw.Triangle:
                        Triangle triangle = (Triangle)drawShape.getShape();
                        if (triangle.getRemainingClick() == 3)
                        {
                            triangle.setPoint1(new Point(round(e.X), round(e.Y)));
                        }
                        else if (triangle.getRemainingClick() == 2)
                        {
                            triangle.setPoint2(new Point(round(e.X), round(e.Y)));
                        }
                        break;

                    case TypeDraw.Parallelogram:
                        Parallelogram parallelogram = (Parallelogram)drawShape.getShape();
                        if (parallelogram.getRemainingClick() == 3)
                        {
                            parallelogram.setPoint1(new Point(round(e.X), round(e.Y)));
                        }
                        else if (parallelogram.getRemainingClick() == 2)
                        {
                            parallelogram.setPoint2(new Point(round(e.X), round(e.Y)));
                        }
                        break;

                    case TypeDraw.Circle:
                        Circle circle = (Circle)drawShape.getShape();
                        circle.setCenterPoint(new Point(round(e.X), round(e.Y)));
                        break;

                    case TypeDraw.Ellipse:
                        Ellipse ellipse = (Ellipse)drawShape.getShape();
                        if (ellipse.getRemainingClick() == 3)
                        {
                            ellipse.setStartPoint(new Point(round(e.X), round(e.Y)));
                        }
                        else if (ellipse.getRemainingClick() == 2)
                        {
                            ellipse.setEndWidthPoint(new Point(round(e.X), round(e.Y)));
                        }
                        break;

                    case TypeDraw.Square:
                        Square square = (Square)drawShape.getShape();
                        square.setPoint1(new Point(round(e.X), round(e.Y)));
                        break;
                    }
                }
                else
                {
                    if (drawShape.getShape().getTransformFlag())
                    {
                        drawShape.getShape().setTransformPoint(new Point(round(e.X), round(e.Y)));
                    }
                    else
                    {
                        switch (drawShape.getShape().getTypeDraw())
                        {
                        case TypeDraw.Line:
                            Line line = (Line)drawShape.getShape();
                            //line.setEndPoint(new Point(Convert.ToInt16(round(e.X)), Convert.ToInt16(round(e.Y))));
                            line.setEndPoint(new Point(round(e.X), round(e.Y)));
                            break;

                        case TypeDraw.Rectangle:
                            Rectangle rectangle = (Rectangle)drawShape.getShape();
                            rectangle.setEndPoint(new Point(round(e.X), round(e.Y)));
                            break;

                        case TypeDraw.Triangle:
                            Triangle triangle = (Triangle)drawShape.getShape();
                            triangle.setPoint3(new Point(round(e.X), round(e.Y)));
                            break;

                        case TypeDraw.Parallelogram:
                            Parallelogram paralleogram = (Parallelogram)drawShape.getShape();
                            paralleogram.setPoint3(new Point(round(e.X), round(e.Y)));
                            break;

                        case TypeDraw.Circle:
                            Circle circle = (Circle)drawShape.getShape();
                            circle.setEndPoint(new Point(round(e.X), round(e.Y)));
                            break;

                        case TypeDraw.Ellipse:
                            Ellipse ellipse = (Ellipse)drawShape.getShape();
                            ellipse.setEndHightPoint(new Point(round(e.X), round(e.Y)));
                            break;

                        case TypeDraw.Cube:
                            //Cube cube = (Cube)drawShape.getShape();
                            //cube.setStartPoint(new Point(round(e.X), round(e.Y)));
                            //new InputCubeForm(drawShape).ShowDialog();
                            return;

                            break;

                        case TypeDraw.Cylinder:
                            //Cylinder cylinder = (Cylinder)drawShape.getShape();
                            //cylinder.setPoint(new Point(round(e.X), round(e.Y)));
                            return;

                            break;

                        case TypeDraw.Square:
                            Square square = (Square)drawShape.getShape();
                            square.setPoint2(new Point(round(e.X), round(e.Y)));
                            break;
                        }
                        drawShape.addShapeToShapeSet();
                        drawShape.resetShape();
                        button9.Enabled  = false;
                        button12.Enabled = false;
                        button14.Enabled = false;
                        button15.Enabled = false;
                        button17.Enabled = false;
                        button13.Enabled = false;
                        if (drawShape.getShapeSet().Count == 0)
                        {
                            button8.Enabled = false;
                        }
                    }
                    panel1.Refresh();
                }
            }
            else if (e.Button == MouseButtons.Right) //cancel and clear the current shape in screen
            {
                drawShape.resetShape();
                //panel1.Paint += new PaintEventHandler(drawShape.paint);
                panel1.Refresh();
            }
        }