private void shapeSymBT_Click(object sender, EventArgs e) { if (listBox1.SelectedItems.Count > 0) { string areaText = ""; List <Area> selectedAreas = new List <Area>(); foreach (object areaObj in listBox1.SelectedItems) { Area area = areaObj as Area; if (!area.IsSubComponent) { area = area.Clone(); AreaMapComponent.AddArea(area); AreaMapComponent.Symmetrize(area); //Search if Area already exists int index = 0; Area existingArea = null; foreach (Area oldArea in AreaMapComponent.CurrentAreaMap.Areas) { if (oldArea.Name == area.Name && area != oldArea) { existingArea = oldArea; break; } index++; } if (existingArea != null) { AreaMapComponent.RemoveAreas(new List <Area> { existingArea }); if (index < AreaMapComponent.CurrentAreaMap.Areas.Count - 1) { AreaMapComponent.CurrentAreaMap.Areas.Remove(area); AreaMapComponent.CurrentAreaMap.Areas.Insert(index, area); } } } } RefreshListBox(); } }