public void ReGroup() { for (int i = 0; i < Selection.Count; i++) { if (Selection[i].GetType().Equals(typeof(GroupShapeImpl))) { GroupShapeImpl group = (GroupShapeImpl)Selection[i]; ShapeList.AddRange(group.SubItem); group.SubItem.Clear(); Selection[i] = null; group = null; ShapeList.Remove(Selection[i]); Selection.Remove(Selection[i]); } } GC.Collect(); }
public void GroupSelected() { if (Selection.Count < 2) { return; } float minX = float.PositiveInfinity; float minY = float.PositiveInfinity; float maxX = float.NegativeInfinity; float maxY = float.NegativeInfinity; foreach (var item in Selection) { if (minX > item.Location.X) { minX = item.Location.X; } if (minY > item.Location.Y) { minY = item.Location.Y; } if (maxX < item.Location.X + item.Width) { maxX = item.Location.X + item.Width; } if (maxY < item.Location.Y + item.Height) { maxY = item.Location.Y + item.Height; } } var group = new GroupShapeImpl(new RectangleF(minX, minY, maxX - minX, maxY - minY)); group.SubItem = Selection; foreach (var item in Selection) { ShapeList.Remove(item); } Selection = new List <Shape>(); Selection.Add(group); ShapeList.Add(group); }