Hi All,

I have this arraylist which I add 2 shape objects to it I also add the shape to a temp array list, why is it that when I change the values in a shape the values in the temp array list also get changed?

Highlighted red is where I add the shapes to the first temp array list
Highlighted blue is where I add the shapes to the second temp array list

VB Code:
  1. Drawable shape;
  2.         int ClickedShape = -1;
  3.         ArrayList primitives = new ArrayList();
  4.         List<ArrayList> Undo = new List<ArrayList>();
  5.         int startx = 0;
  6.         int starty = 0;
  7.         bool CanMove = false;
  8.         int UndoPosition = 0;
  9.  
  10.         private void button1_Click(object sender, EventArgs e)
  11.         {
  12.  
  13.             GraphicsPath path = new GraphicsPath();
  14.             Rectangle r = new Rectangle(10, 10, 45, 45);
  15.             path.AddRectangle(r);
  16.             primitives.Add(new Shape(path, Color.Red));
  17.  
  18.  
  19.             GraphicsPath path2 = new GraphicsPath();
  20.             Rectangle r2 = new Rectangle(50, 10, 45, 45);
  21.             path2.AddRectangle(r2);
  22.             primitives.Add(new Shape(path2, Color.Green));
  23.  
  24.            
  25.             Draw();
  26.  
  27.             [COLOR=Red]ArrayList Temp = new ArrayList();
  28.             foreach (Shape s in primitives)
  29.             {
  30.                 Shape te = new Shape(s.GraphicsPath, s.Color);
  31.                 Temp.Add(te);
  32.             }
  33.             Undo.Add(Temp);[/COLOR]        }
  34.  
  35.         private void button2_Click(object sender, EventArgs e)
  36.         {
  37.             primitives.Reverse(ClickedShape, 2);
  38.             Draw();
  39.         }
  40.  
  41.         private void pane1_MouseMove(object sender, MouseEventArgs e)
  42.         {
  43.             if (CanMove == true)
  44.             {
  45.                 shape = ((Drawable)(primitives[ClickedShape]));
  46.                 shape.Move(new Point(e.X, e.Y), new Point(startx, starty));
  47.                 Draw();
  48.             }
  49.         }
  50.  
  51.         private void pane1_MouseDown(object sender, MouseEventArgs e)
  52.         {
  53.            
  54.            
  55.             foreach (Shape s in primitives)
  56.             {
  57.                 if(s.GraphicsPath.IsVisible(e.X,e.Y))
  58.                 {
  59.                     CanMove = true;
  60.                     ClickedShape = primitives.IndexOf(s);
  61.                     shape = ((Drawable)(primitives[ClickedShape]));
  62.                    
  63.                 }
  64.             }
  65.             startx = e.X - (int)shape.GraphicsPath.GetBounds().X;
  66.             starty = e.Y - (int)shape.GraphicsPath.GetBounds().Y;
  67.         }
  68.  
  69.         private void pane1_MouseUp(object sender, MouseEventArgs e)
  70.         {
  71.             CanMove = false;
  72.             [COLOR=RoyalBlue]ArrayList Temp = new ArrayList();
  73.             foreach (Shape s in primitives)
  74.             {
  75.                 Shape te = new Shape(s.GraphicsPath, s.Color);
  76.                 Temp.Add(te);
  77.             }
  78.            
  79.             Undo.Add(Temp);[/COLOR]
  80.         }
  81.  
  82.         public void Draw()
  83.         {
  84.             Bitmap bat = new Bitmap(pane1.TempImage, pane1.Width, pane1.Height);
  85.             Image d = bat;
  86.             Graphics graphics = Graphics.FromImage(d);
  87.             Drawable shapepy;
  88.             for (int i = 0; i <= primitives.Count - 1; i++)
  89.             {
  90.                 shapepy = ((Drawable)(primitives[i]));
  91.                 graphics.SmoothingMode = SmoothingMode.AntiAlias;
  92.                 graphics.FillPath(new SolidBrush(Color.FromArgb(255, shapepy.Color.R, shapepy.Color.G, shapepy.Color.B)), shapepy.GraphicsPath);
  93.                 graphics.DrawPath(new Pen(shapepy.Color, 2), shapepy.GraphicsPath);
  94.             }
  95.  
  96.             pane1.Image = d;
  97.         }
  98.  
  99.  
  100.         private Image _Image()
  101.         {
  102.             Bitmap b = new Bitmap(pane1.Width, pane1.Height);
  103.             Rectangle rect2 = new Rectangle(0, 0, pane1.Width, pane1.Height);
  104.             pane1.DrawToBitmap(b, rect2);
  105.  
  106.             return b;
  107.         }