コード例 #1
0
        private void MainCAD_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && chosenShape != Shapes.Point)
            {
                xEnd = e.X;
                yEnd = e.Y;
                int deltaX = xEnd - xStart;
                int deltaY = yEnd - yStart;

                switch (chosenShape)
                {
                case Shapes.Line:
                    Point start = new Point(xStart, yStart);
                    Point end   = new Point(xEnd, yEnd);
                    Line  line  = new Line(start, end, chosenColor);
                    line.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    shapeList.Add(line);
                    break;

                case Shapes.Rectangle:
                    start = new Point(xStart, yStart);
                    Rectangle rectangle = new Rectangle(chosenColor, start, deltaX, deltaY);
                    rectangle.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    shapeList.Add(rectangle);
                    break;

                case Shapes.Square:
                    start = new Point(xStart, yStart);
                    Square square = new Square(chosenColor, start, deltaX);
                    square.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    shapeList.Add(square);
                    break;

                case Shapes.Ellipsis:

                    if (ctrlKeyDown)
                    {
                        deltaY = deltaX = Math.Max(deltaX, deltaY);
                    }

                    start = new Point(xStart, yStart);
                    Ellipsis ellipsis = new Ellipsis(chosenColor, start, deltaX, deltaY);
                    ellipsis.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    shapeList.Add(ellipsis);
                    break;
                }
            }
        }
コード例 #2
0
        private void MainCAD_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point start = new Point(xStart, yStart, chosenColor);
                Point end   = new Point(xEnd, yEnd, chosenColor);
                int   deltaX;
                int   deltaY;

                switch (chosenShape)
                {
                case Shapes.Point:
                    end = new Point(e.X, e.Y, chosenColor);
                    end.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    shapeList.Add(end);
                    break;

                case Shapes.Line:
                    //Cancella la vecchia linea disegnandone una nuova dello stesso colore
                    Line line = new Line(start, end, BackColor);
                    line.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    //Disegna la nuova linea
                    xEnd = e.X;
                    yEnd = e.Y;
                    end  = new Point(xEnd, yEnd, chosenColor);
                    line = new Line(start, end, chosenColor);
                    line.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    RenderRefresh();
                    break;

                case Shapes.Rectangle:
                {
                    //Cancella il vecchio rettangolo
                    deltaX = xEnd - xStart;
                    deltaY = yEnd - yStart;

                    Rectangle rectangle =
                        new Rectangle(BackColor, new Point(xStart, yStart, chosenColor), deltaX, deltaY);
                    rectangle.Draw(toolStripContainer1.ContentPanel.CreateGraphics());

                    //Aggiorna la posizione del mouse
                    xEnd      = e.X;
                    yEnd      = e.Y;
                    deltaX    = xEnd - xStart;
                    deltaY    = yEnd - yStart;
                    rectangle = new Rectangle(chosenColor, new Point(xStart, yStart, chosenColor), deltaX, deltaY);
                    rectangle.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    RenderRefresh();
                }
                break;

                case Shapes.Square:
                    deltaX = xEnd - xStart;
                    Square square = new Square(BackColor, new Point(xStart, yStart), deltaX);
                    square.Draw(toolStripContainer1.ContentPanel.CreateGraphics());

                    xEnd   = e.X;
                    yEnd   = e.Y;
                    deltaX = xEnd - xStart;
                    square = new Square(chosenColor, new Point(xStart, yStart, chosenColor), deltaX);
                    square.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    RenderRefresh();
                    break;

                case Shapes.Ellipsis:
                    deltaX = xEnd - xStart;
                    deltaY = yEnd - yStart;

                    if (ctrlKeyDown)
                    {
                        deltaX = deltaY = Math.Max(deltaX, deltaY);
                    }

                    Ellipsis ellipsis = new Ellipsis(BackColor, new Point(xStart, yStart, chosenColor), deltaX, deltaY);
                    ellipsis.Draw(toolStripContainer1.ContentPanel.CreateGraphics());

                    xEnd   = e.X;
                    yEnd   = e.Y;
                    deltaX = xEnd - xStart;
                    deltaY = yEnd - yStart;

                    if (ctrlKeyDown)
                    {
                        deltaY = deltaX = Math.Max(deltaX, deltaY);
                    }

                    ellipsis = new Ellipsis(chosenColor, new Point(xStart, yStart, chosenColor), deltaX, deltaY);
                    ellipsis.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    RenderRefresh();
                    break;
                }
            }
        }