Example #1
0
        private void Scene_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (ContainFigure == false)
            {
                MessageBox.Show("There are not selected figure!");
            }

            else
            {
                if (_selectedShape != null)
                {
                    var TypeOfFigure = _selectedShape.GetType();
                    if (TypeOfFigure.Equals(typeof(DrawFigure)) && _selectedShape.Height != _selectedShape.Width)
                    {
                        Rectangle rectangle = new Rectangle();
                        rectangle.textBox1.Text = _selectedShape.Width.ToString();
                        rectangle.textBox2.Text = _selectedShape.Height.ToString();
                        rectangle.ShowDialog();
                        ElementFromScene1 = rectangle.Element1;
                        ElementFromScene2 = rectangle.Element2;
                        FigureFromScene   = rectangle.FigureChoosed;
                        ColorFromScene    = rectangle.Color;

                        Shape drawrectangle = new DrawFigure();
                        drawrectangle.Position = e.Location;
                        drawrectangle.Height   = ElementFromScene1;
                        drawrectangle.Width    = ElementFromScene2;
                        drawrectangle.Color    = ColorFromScene;
                        drawrectangle.Order    = _shapes
                                                 .Select(s => s.Order)
                                                 .OrderBy(o => o)
                                                 .LastOrDefault() + 1;

                        drawrectangle.ConstColor = drawrectangle.Color;
                        AddShape(drawrectangle);
                    }
                    else if (TypeOfFigure.Equals(typeof(DrawFigure)) && _selectedShape.Height == _selectedShape.Width)
                    {
                        Square square = new Square();
                        square.textBox1.Text = _selectedShape.Height.ToString();
                        square.ShowDialog();
                        ElementFromScene1 = square.Element1;
                        FigureFromScene   = square.FigureChoosed;
                        ColorFromScene    = square.Color;

                        Shape drawsquare = new DrawFigure();
                        drawsquare.Position = e.Location;
                        drawsquare.Width    = ElementFromScene1;
                        drawsquare.Height   = ElementFromScene1;
                        drawsquare.Color    = ColorFromScene;
                        drawsquare.Order    = _shapes
                                              .Select(s => s.Order)
                                              .OrderBy(o => o)
                                              .LastOrDefault() + 1;

                        drawsquare.ConstColor = drawsquare.Color;
                        AddShape(drawsquare);
                    }
                    else if (TypeOfFigure.Equals(typeof(DrawTriangle)))
                    {
                        Triangle triangle = new Triangle();
                        triangle.textBox1.Text = _selectedShape.Width.ToString();
                        triangle.textBox2.Text = _selectedShape.Height.ToString();
                        triangle.textBox3.Text = _selectedShape.Side3.ToString();
                        triangle.ShowDialog();
                        ElementFromScene1 = triangle.Element1;
                        ElementFromScene2 = triangle.Element2;
                        ElementFromScene3 = triangle.Element3;
                        FigureFromScene   = triangle.FigureChoosed;
                        ColorFromScene    = triangle.Color;

                        Shape drawTriangle = new DrawTriangle();
                        drawTriangle.Position = e.Location;
                        drawTriangle.Width    = ElementFromScene1;
                        drawTriangle.Height   = ElementFromScene2;
                        drawTriangle.Side3    = ElementFromScene3;
                        drawTriangle.Color    = ColorFromScene;
                        drawTriangle.Order    = _shapes
                                                .Select(s => s.Order)
                                                .OrderBy(o => o)
                                                .LastOrDefault() + 1;

                        drawTriangle.ConstColor = drawTriangle.Color;
                        AddShape(drawTriangle);
                    }
                    else if (TypeOfFigure.Equals(typeof(DrawCircle)))
                    {
                        Circle circle = new Circle();
                        circle.textBox1.Text = _selectedShape.Height.ToString();
                        circle.ShowDialog();
                        ElementFromScene1 = circle.Element1;
                        FigureFromScene   = circle.FigureChoosed;
                        ColorFromScene    = circle.Color;

                        Shape drawCircle = new DrawCircle();
                        drawCircle.Position = e.Location;
                        drawCircle.Position = e.Location;
                        drawCircle.Height   = ElementFromScene1;
                        drawCircle.Width    = ElementFromScene1;
                        drawCircle.Color    = ColorFromScene;
                        drawCircle.Order    = _shapes
                                              .Select(s => s.Order)
                                              .OrderBy(o => o)
                                              .LastOrDefault() + 1;

                        drawCircle.ConstColor = drawCircle.Color;
                        AddShape(drawCircle);
                    }

                    _shapes.Remove(_selectedShape);
                }
            }
        }
Example #2
0
        private void Scene_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (FigureFromScene == 0)
                {
                    MessageBox.Show("Choose Radio Button!");
                }
                if (FigureFromScene == 1)
                {
                    Shape drawTriangle = new DrawTriangle();
                    drawTriangle.Position = e.Location;
                    drawTriangle.Width    = ElementFromScene1;
                    drawTriangle.Height   = ElementFromScene2;
                    drawTriangle.Side3    = ElementFromScene3;
                    drawTriangle.Color    = ColorFromScene;
                    drawTriangle.Order    = _shapes
                                            .Select(s => s.Order)
                                            .OrderBy(o => o)
                                            .LastOrDefault() + 1;

                    drawTriangle.ConstColor = drawTriangle.Color;
                    AddShape(drawTriangle);
                }
                else if (FigureFromScene == 2)
                {
                    Shape drawsquare = new DrawFigure();
                    drawsquare.Position = e.Location;
                    drawsquare.Width    = ElementFromScene1;
                    drawsquare.Height   = ElementFromScene1;
                    drawsquare.Color    = ColorFromScene;
                    drawsquare.Order    = _shapes
                                          .Select(s => s.Order)
                                          .OrderBy(o => o)
                                          .LastOrDefault() + 1;

                    drawsquare.ConstColor = drawsquare.Color;
                    AddShape(drawsquare);
                }
                else if (FigureFromScene == 3)
                {
                    Shape drawrectangle = new DrawFigure();
                    drawrectangle.Position = e.Location;
                    drawrectangle.Height   = ElementFromScene1;
                    drawrectangle.Width    = ElementFromScene2;
                    drawrectangle.Color    = ColorFromScene;
                    drawrectangle.Order    = _shapes
                                             .Select(s => s.Order)
                                             .OrderBy(o => o)
                                             .LastOrDefault() + 1;

                    drawrectangle.ConstColor = drawrectangle.Color;
                    AddShape(drawrectangle);
                }
                else if (FigureFromScene == 4)
                {
                    Shape drawCircle = new DrawCircle();
                    drawCircle.Position = e.Location;
                    drawCircle.Position = e.Location;
                    drawCircle.Height   = ElementFromScene1;
                    drawCircle.Width    = ElementFromScene1;
                    drawCircle.Color    = ColorFromScene;
                    drawCircle.Order    = _shapes
                                          .Select(s => s.Order)
                                          .OrderBy(o => o)
                                          .LastOrDefault() + 1;

                    drawCircle.ConstColor = drawCircle.Color;
                    AddShape(drawCircle);
                }
            }
            else if (e.Button == MouseButtons.Left)
            {
                _mouseDownLocationLeft = e.Location;

                _selectedShape = _shapes
                                 .OrderByDescending(o => o.Order)
                                 .Where(shape => shape.Contains(e.Location))
                                 .FirstOrDefault();

                if (_selectedShape != null)
                {
                    _selectedShape.Color = BackColor;
                    ContainFigure        = true;
                }

                _selectedFigures = WhereContains(e.Location);

                _tracingMouseLeft = true;
            }
            Invalidate();
        }