Exemple #1
0
        private void FormScene_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var graphics = CreateGraphics();

            if (e.Button == MouseButtons.Right)
            {
                switch (FormFigure.Figure)
                {
                case 1:
                    Shape rectangle = new Figures.Rectangle(e.Location, FormRectangle.el1, FormRectangle.el2, FormRectangle.buttonCollor);
                    rectangle.ConstColoring = FormRectangle.buttonCollor;
                    _figures.Add(rectangle);
                    break;

                case 2:
                    Shape square = new Square(e.Location, FormSquare.el1, FormSquare.el1, FormSquare.buttonCollor);
                    square.ConstColoring = FormSquare.buttonCollor;
                    _figures.Add(square);
                    break;

                case 3:
                    Shape cicrle = new Circle(e.Location, FormCircle.el1, FormCircle.el1, FormCircle.buttonCollor);
                    cicrle.ConstColoring = FormCircle.buttonCollor;
                    _figures.Add(cicrle);
                    break;

                case 4:
                    Shape triangle = new Triangle(e.Location, FormTriangle.el1, FormTriangle.el2, FormTriangle.buttonCollor, FormTriangle.el3);
                    triangle.ConstColoring = FormTriangle.buttonCollor;
                    _figures.Add(triangle);
                    break;

                case 5:
                    Shape ellipse = new Еllipse(e.Location, FormEllipse.el1, FormEllipse.el2, FormEllipse.buttonCollor);
                    ellipse.ConstColoring = FormEllipse.buttonCollor;
                    _figures.Add(ellipse);
                    break;
                }
            }

            if (e.Button == MouseButtons.Left)
            {
                var clickedfigure = _figures
                                    .OrderByDescending(o => o.Order)
                                    .Where(shape => shape.Contain(e.Location))
                                    .LastOrDefault();
                if (clickedfigure != null)
                {
                    if (clickedfigure.GetType() == typeof(Figures.Rectangle))
                    {
                        FormRectangle formRectangle = new FormRectangle();
                        FormRectangle.formrectangle.WriteLog(clickedfigure.Aheigth.ToString(), clickedfigure.Bwidth.ToString());
                        if (formRectangle.ShowDialog() == DialogResult.OK)
                        {
                            clickedfigure.Aheigth       = FormRectangle.el1;
                            clickedfigure.Bwidth        = FormRectangle.el2;
                            clickedfigure.Color         = FormRectangle.buttonCollor;
                            clickedfigure.ConstColoring = FormRectangle.buttonCollor;
                        }
                    }
                    else if (clickedfigure.GetType() == typeof(Square))
                    {
                        FormSquare formSquare = new FormSquare();
                        FormSquare.formsquare.WriteLog(clickedfigure.Aheigth.ToString());

                        if (formSquare.ShowDialog() == DialogResult.OK)
                        {
                            clickedfigure.Aheigth       = FormSquare.el1;
                            clickedfigure.Bwidth        = FormSquare.el1;
                            clickedfigure.Color         = FormSquare.buttonCollor;
                            clickedfigure.ConstColoring = FormSquare.buttonCollor;
                        }
                    }
                    else if (clickedfigure.GetType() == typeof(Circle))
                    {
                        FormCircle formCircle = new FormCircle();
                        FormCircle.formcircle.WriteLog(clickedfigure.Aheigth.ToString());
                        if (formCircle.ShowDialog() == DialogResult.OK)
                        {
                            clickedfigure.Aheigth       = FormCircle.el1;
                            clickedfigure.Color         = FormCircle.buttonCollor;
                            clickedfigure.ConstColoring = FormCircle.buttonCollor;
                        }
                    }
                    else if (clickedfigure.GetType() == typeof(Triangle))
                    {
                        FormTriangle formTriangle = new FormTriangle();
                        FormTriangle.formtriangle.WriteLog(clickedfigure.Aheigth.ToString(), clickedfigure.Bwidth.ToString(), clickedfigure.C.ToString());;
                        if (formTriangle.ShowDialog() == DialogResult.OK)
                        {
                            clickedfigure.Aheigth       = FormTriangle.el1;
                            clickedfigure.Bwidth        = FormTriangle.el2;
                            clickedfigure.C             = FormTriangle.el3;
                            clickedfigure.Color         = FormTriangle.buttonCollor;
                            clickedfigure.ConstColoring = FormTriangle.buttonCollor;
                        }
                    }
                    else if (clickedfigure.GetType() == typeof(Еllipse))
                    {
                        FormEllipse formEllipse = new FormEllipse();
                        FormEllipse.formellipse.WriteLog(clickedfigure.Aheigth.ToString(), clickedfigure.Bwidth.ToString());
                        if (formEllipse.ShowDialog() == DialogResult.OK)
                        {
                            clickedfigure.Aheigth       = FormEllipse.el1;
                            clickedfigure.Bwidth        = FormEllipse.el2;
                            clickedfigure.Color         = FormEllipse.buttonCollor;
                            clickedfigure.ConstColoring = FormEllipse.buttonCollor;
                        }
                    }
                }
            }
            foreach (var figure in _figures)
            {
                figure.Paint(graphics);
                textBoxCircum.Text = figure.CalculateCircum().ToString();
                textBoxArea.Text   = figure.CalculateArea().ToString();
                textBoxSide.Text   = figure.GetTypeSide();
                OrderFigure_Avg();
                AreaAtAll();
            }
            Invalidate();
        }
 public FormRectangle()
 {
     InitializeComponent();
     formrectangle = this;
 }