Example #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            string s = textBox1.Text;
            string z = textBox2.Text;

            a = Convert.ToInt32(s);
            b = Convert.ToInt32(z);
            string selected = comboBox1.SelectedItem.ToString();

            if (selected[0] == 'l')
            {
                char last  = selected[selected.Length - 1];
                int  index = (int)Char.GetNumericValue(last);
                index--;

                myLine line = listOfLines[index];
                line.translate(a, -1 * b);

                listOfLines[index] = line;
                pictureBox1.Invalidate();
            }
            else if (selected[0] == 'c')
            {
                char last  = selected[selected.Length - 1];
                int  index = (int)Char.GetNumericValue(last);
                index--;

                myCircle circle = listOfCircles[index];
                circle.translate(a, -1 * b);

                listOfCircles[index] = circle;
                pictureBox1.Invalidate();
            }
            else if (selected[0] == 't')
            {
                char last  = selected[selected.Length - 1];
                int  index = (int)Char.GetNumericValue(last);
                index--;

                myTriangle triangle = listOfTriangles[index];
                triangle.translate(a, -1 * b);

                listOfTriangles[index] = triangle;
                pictureBox1.Invalidate();
            }
            else if (selected[0] == 's')
            {
                char last  = selected[selected.Length - 1];
                int  index = (int)Char.GetNumericValue(last);
                index--;

                mySquare square = listOfSquares[index];
                square.translate(a, -1 * b);

                listOfSquares[index] = square;
                pictureBox1.Invalidate();
            }
            else if (selected[0] == 'r')
            {
                char last  = selected[selected.Length - 1];
                int  index = (int)Char.GetNumericValue(last);
                index--;

                myRectangle rectangle = listOfRectangles[index];
                rectangle.translate(a, -1 * b);

                listOfRectangles[index] = rectangle;
                pictureBox1.Invalidate();
            }
            else if (selected[0] == 'h' && selected[2] == 'p')
            {
                char last  = selected[selected.Length - 1];
                int  index = (int)Char.GetNumericValue(last);
                index--;

                myHeptagon heptagon = listOfHeptagons[index];
                heptagon.translate(a, -1 * b);

                listOfHeptagons[index] = heptagon;
                pictureBox1.Invalidate();
            }
            else if (selected[0] == 'h' && selected[2] == 'x')
            {
                char last  = selected[selected.Length - 1];
                int  index = (int)Char.GetNumericValue(last);
                index--;

                myHexagon hexagon = listOfHexagons[index];
                hexagon.translate(a, -1 * b);

                listOfHexagons[index] = hexagon;
                pictureBox1.Invalidate();
            }
            else if (selected[0] == 'e')
            {
                char last  = selected[selected.Length - 1];
                int  index = (int)Char.GetNumericValue(last);
                index--;

                myEllipse ellipse = listOfEllipses[index];
                ellipse.translate(a, -1 * b);

                listOfEllipses[index] = ellipse;
                pictureBox1.Invalidate();
            }
            else if (selected[0] == 'o')
            {
                char last  = selected[selected.Length - 1];
                int  index = (int)Char.GetNumericValue(last);
                index--;

                myOctagon octagon = listOfOctagons[index];
                octagon.translate(a, -1 * b);

                listOfOctagons[index] = octagon;
                pictureBox1.Invalidate();
            }
            else if (selected[0] == 'p' && selected[2] == 'n')
            {
                char last  = selected[selected.Length - 1];
                int  index = (int)Char.GetNumericValue(last);
                index--;

                myPentagon pentagon = listOfPentagons[index];
                pentagon.translate(a, -1 * b);

                listOfPentagons[index] = pentagon;
                pictureBox1.Invalidate();
            }
            else if (selected[0] == 'p' && selected[2] == 't')
            {
                char last  = selected[selected.Length - 1];
                int  index = (int)Char.GetNumericValue(last);
                index--;

                myPetal petal = listOfPetals[index];
                petal.translate(a, -1 * b);

                listOfPetals[index] = petal;
                pictureBox1.Invalidate();
            }
        }
Example #2
0
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            g = e.Graphics;
            //myPen.Width = 3;

            if (flag)
            {
                switch (shape)
                {
                case "line":
                    myLine line = new myLine(p, p2, width, color);
                    line.draw(g, myPen);
                    break;

                case "circle":
                    myCircle circle = new myCircle(p, p2, width, color);
                    circle.draw(g, myPen);
                    break;

                case "triangle":
                    myTriangle triangle = new myTriangle(p, p2, width, color);
                    triangle.draw(g, myPen);
                    break;

                case "square":
                    mySquare square = new mySquare(p, p2, width, color);
                    square.draw(g, myPen);
                    break;

                case "rectangle":
                    myRectangle rectangle = new myRectangle(p, p2, width, color);
                    rectangle.draw(g, myPen);
                    break;

                case "pentagon":
                    myPentagon pentagon = new myPentagon(p, p2, width, color);
                    pentagon.draw(g, myPen);
                    break;

                case "octagon":
                    myOctagon octagon = new myOctagon(p, p2, width, color);
                    octagon.draw(g, myPen);
                    break;

                case "hexagon":
                    myHexagon hexagon = new myHexagon(p, p2, width, color);
                    hexagon.draw(g, myPen);
                    break;

                case "heptagon":
                    myHeptagon heptagon = new myHeptagon(p, p2, width, color);
                    heptagon.draw(g, myPen);
                    break;

                case "ellipse":
                    myEllipse ellipse = new myEllipse(p, p2, width, color);
                    ellipse.draw(g, myPen);
                    break;

                case "petal":
                    myPetal petal = new myPetal(p, p2, width, color);
                    petal.draw(g, myPen);
                    break;

                    /*case "nonagon":
                     *  myNonagon nonagon = new myNonagon(p, p2,width,color);
                     *  nonagon.draw(g, myPen);
                     *  break;
                     */
                }
            }
            /////// for each
            foreach (myLine line in listOfLines)
            {
                line.draw(g, myPen);
            }

            foreach (myCircle circle in listOfCircles)
            {
                circle.draw(g, myPen);
            }
            foreach (myTriangle triangle in listOfTriangles)
            {
                triangle.draw(g, myPen);
            }
            foreach (mySquare square in listOfSquares)
            {
                square.draw(g, myPen);
            }
            foreach (myRectangle rectangle in listOfRectangles)
            {
                rectangle.draw(g, myPen);
            }
            foreach (myPentagon pentagon in listOfPentagons)
            {
                pentagon.draw(g, myPen);
            }
            foreach (myOctagon octagon in listOfOctagons)
            {
                octagon.draw(g, myPen);
            }
            foreach (myHexagon hexagon in listOfHexagons)
            {
                hexagon.draw(g, myPen);
            }

            foreach (myHeptagon heptagon in listOfHeptagons)
            {
                heptagon.draw(g, myPen);
            }

            foreach (myEllipse ellipse in listOfEllipses)
            {
                ellipse.draw(g, myPen);
            }
            foreach (myPetal petal in listOfPetals)
            {
                petal.draw(g, myPen);
            }

            /*           foreach (myNonagon nonagon in listOfNonagon)
             *         {
             *             nonagon.draw(g, myPen);
             *         }
             */
        }