public void Paste() { foreach (var item in CopyData.ToList()) { if (item.GetType() == typeof(RectangleShape)) { RectangleShape rect = new RectangleShape(new Rectangle((int)item.Location.X + 200, (int)item.Location.Y, 100, 200)) { BorderColor = item.BorderColor, FillColor = item.FillColor, Height = item.Height, Width = item.Width, Rotation = item.Rotation }; ShapeList.Add(rect); } else if (item.GetType() == typeof(EllipseShape)) { EllipseShape ellipse = new EllipseShape(new Rectangle((int)item.Location.X + 200, (int)item.Location.Y, 100, 200)) { BorderColor = item.BorderColor, FillColor = item.FillColor, Height = item.Height, Width = item.Width, Rotation = item.Rotation }; ShapeList.Add(ellipse); } else if (item.GetType() == typeof(TriangleShape)) { TriangleShape triangle = new TriangleShape(new Rectangle((int)item.Location.X + 200, (int)item.Location.Y, 100, 200)) { PercentX = item.PercentX, PercentY = item.PercentY, IsBeingResized = item.IsBeingResized, Point1 = item.Point1, Point2 = item.Point2, x1 = item.x1, x2 = item.x2, x3 = item.x3, y1 = item.y1, y2 = item.y2, y3 = item.y3, Polygon = item.Polygon, TriangleSize = item.TriangleSize, BorderColor = item.BorderColor, FillColor = item.FillColor, Height = item.Height, Width = item.Width, Rotation = item.Rotation }; ShapeList.Add(triangle); } else if (item.GetType() == typeof(LineShape)) { LineShape line = new LineShape(new Rectangle((int)item.Location.X + 200, (int)item.Location.Y, 100, 200)) { x1 = item.x2, x2 = item.x2, y1 = item.y1, y2 = item.y2, LineSize = item.LineSize, Point1 = item.Point1, Point2 = item.Point2, IsBeingResized = item.IsBeingResized, Polygon = item.Polygon, TriangleSize = item.TriangleSize, BorderColor = item.BorderColor, FillColor = item.FillColor, Height = item.Height, Width = item.Width, Rotation = item.Rotation }; ShapeList.Add(line); } else if (item.GetType() == typeof(TrapezoidShape)) { TrapezoidShape trape = new TrapezoidShape(new Rectangle((int)item.Location.X + 200, (int)item.Location.Y, 100, 200)) { LineSize = item.LineSize, Polygon = item.Polygon, TriangleSize = item.TriangleSize, BorderColor = item.BorderColor, FillColor = item.FillColor, Height = item.Height, Width = item.Width, Rotation = item.Rotation }; ShapeList.Add(trape); } } }
public void AddRandomTrape() { Random rnd = new Random(); int x = rnd.Next(100, 1000); //Generate random position for the rectangle int y = rnd.Next(100, 600); PointF p1 = new PointF(); PointF p2 = new PointF(); PointF p3 = new PointF(); PointF p4 = new PointF(); p1.X = 200; p1.Y = 100; p2.X = 50; p2.Y = 100; p3.X = 0; p3.Y = 250; p4.X = 250; p4.Y = 250; PointF[] edges = new PointF[4]; edges[0] = p1; edges[1] = p2; edges[2] = p3; edges[3] = p4; int x1 = 10000; //leftmost x Unused int x2 = 0; //rightmost x for (int i = 0; i < edges.Length; i++) { if (edges[i].X < x1) { x1 = (Int32)edges[i].X; } if (edges[i].X > x2) { x2 = (Int32)edges[i].X; } } int y1 = 10000; //top y Unused int y2 = 0; //bottom y for (int i = 0; i < edges.Length; i++) { if (edges[i].Y < y1) { y1 = (Int32)edges[i].Y; } if (edges[i].Y > y2) { y2 = (Int32)edges[i].Y; } } TrapezoidShape trape = new TrapezoidShape(new Rectangle(x, y, x2, y2)); trape.Edges(p1, p2, p3, p4); trape.FillColor = ColorFill; trape.Rotation = Rotation; trape.BorderColor = ColorBorder; // triangle.Size = p2x; ShapeList.Add(trape); }