Beispiel #1
0
        //copy constructor
        public Drawing(Drawing d)
        {
            InitializeComponent();
            ClientSize = d.ClientSize;
            myImage = d.myImage;
            myShapes = new ArrayList();

            //copy each shape in list
            foreach (Shape s in d.myShapes)
            {
                myShape = new Rect(0,0,1,1,Color.Black);
                //is s a rectangle...?
                if (myShape.GetType() == s.GetType()) myShape = new Rect((Rect)s);
                else
                {
                    //is it an oval...?
                    myShape = new Oval(0,0,1,1,Color.Black);
                    if (myShape.GetType() == s.GetType()) myShape = new Oval((Oval)s);
                    else
                    {
                        //is it a line...?
                        myShape = new Segment(0,0,1,1,Color.Black,1);
                        if (myShape.GetType() == s.GetType()) myShape = new Segment((Segment)s);
                        else
                        {
                            //is it a triangle...?
                            Point p1 = new Point();
                            Point p2 = new Point();
                            Point p3 = new Point();
                            myShape = new Triangle(p1,p2,p3,Color.Black);
                            if (myShape.GetType() == s.GetType()) myShape = new Triangle((Triangle)s);
                        }
                    }
                }

                myShape.MyColor = s.MyColor;
                myShape.MyCenter = s.MyCenter;
                myShapes.Add(myShape);
            }

            myShape = d.myShape;
            offGraphics = d.offGraphics;
            visGraphics = d.visGraphics;
            offBitmap = d.offBitmap;

            offGraphics = Graphics.FromImage(offBitmap);

            myColor = d.myColor;
        }
Beispiel #2
0
 public void copy(Shape s)
 {
     Shape temp;
     if (s!=null)
     {
         temp = new Rect(0,0,1,1,Color.Black);
         //is s a rectangle...?
         if (temp.GetType() == s.GetType()) temp = new Rect((Rect)s);
         else
         {
             //is it an oval...?
             temp = new Oval(0,0,1,1,Color.Black);
             if (temp.GetType() == s.GetType()) temp = new Oval((Oval)s);
             else
             {
                 //is it a line...?
                 temp = new Segment(0,0,1,1,Color.Black,1);
                 if (temp.GetType() == s.GetType()) temp = new Segment((Segment)s);
                 else
                 {
                     //is it a triangle...?
                     Point p1 = new Point();
                     Point p2 = new Point();
                     Point p3 = new Point();
                     temp = new Triangle(p1,p2,p3,Color.Black);
                     if (temp.GetType() == s.GetType()) temp = new Triangle((Triangle)s);
                 }
             }
         }
         //put the brand new copy into myShapes right after(above in the picture) the original
         myShapes.Insert(myShapes.IndexOf(s)+1,temp);
     }
     //if s is null, do nothing
     return;
 }