public void Refresh()
        {
            var g = panel1.CreateGraphics();

            g.Clear(panel1.BackColor);

            foreach (var item in shapes)
            {
                if (item is rectangle)
                {
                    rectangle r = (rectangle)item;
                    r.Draw(g);
                }
                else if (item is circle)
                {
                    circle c = (circle)item;
                    c.Draw(g);
                }
                else if (item is ellipse)
                {
                    ellipse e = (ellipse)item;
                    e.Draw(g);
                }
                else if (item is line)
                {
                    line l = (line)item;
                    l.Draw(g);
                }
                else if (item is polygon)
                {
                    polygon p = (polygon)item;
                    p.Draw(g);
                }
            }
        }
      public override object Clone()
      {
          var r = new rectangle();

          r.x         = x;
          r.y         = y;
          r.width     = width;
          r.height    = height;
          r.thickness = thickness;
          r.color     = color;
          r.fillcolor = fillcolor;
          return(r);
      }
        private void button1_Click(object sender, EventArgs e)
        {
            rectangle r = new rectangle
            {
                x         = 34,
                y         = 34,
                width     = 54,
                height    = 34,
                thickness = 1,
                color     = Color.DarkCyan,
                fillcolor = Color.Gainsboro,
            };


            propertyGrid1.SelectedObject = r;

            shapes.Add(r);
            Refresh();
        }