diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs index d8e5a67..f0335c6 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs @@ -39,10 +39,23 @@ namespace AirplaneWithRadar ReloadObjects(); } + private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) + { + pictureBoxCollection.Image = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes(); + } private void buttonDelObject_Click(object sender, EventArgs e) { - pictureBoxCollection.Image = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes(); + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + if (MessageBox.Show($"Удалить объект { listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) +{ + storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty); + ReloadObjects(); + } + } private void ButtonAddAirplane_Click(object sender, EventArgs e) { @@ -110,10 +123,5 @@ namespace AirplaneWithRadar } pictureBoxCollection.Image = obj.ShowAirplanes(); } - - private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) - { - pictureBoxCollection.Image = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes(); - } } }