private void shapeRemoveBT_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) { selectedAreas.Add(area); areaText += areaObj.ToString() + ","; } } if (MessageBox.Show("Are you sure you want to remove " + areaText.Substring(0, areaText.Length - 1) + " ?", "Remove shapes", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { AreaMapComponent.RemoveAreas(selectedAreas); RefreshListBox(); } else { MessageBox.Show("Nothing to remove, please select some items!"); } } }
private void shapeSymYBT_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.SymmetrizeY(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(); } }