From a9f381a84f71ef629927fe243c47cbc22e5483b2 Mon Sep 17 00:00:00 2001 From: Semka Date: Mon, 14 Nov 2022 02:12:00 +0400 Subject: [PATCH] Event work --- .../GasolineTanker/FormMapWithSetTankers.cs | 26 ++++++++++--------- .../GasolineTanker/TankerDelegate.cs | 10 +++++++ 2 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 GasolineTanker/GasolineTanker/TankerDelegate.cs diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetTankers.cs b/GasolineTanker/GasolineTanker/FormMapWithSetTankers.cs index f3f77da..2a0c424 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetTankers.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetTankers.cs @@ -88,24 +88,26 @@ namespace GasolineTanker } private void ButtonAddTanker_Click(object sender, EventArgs e) + { + var formTankerConfig = new FormTankerConfig(); + formTankerConfig.AddEvent(InsertTankerCheck); + formTankerConfig.Show(); + } + private void InsertTankerCheck(DrawningTanker _tanker) { if (listBoxMaps.SelectedIndex == -1) { return; } - FormTanker form = new(); - if (form.ShowDialog() == DialogResult.OK) + DrawningObjectTanker tanker = new(_tanker); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + tanker >= 0) { - DrawningObjectTanker tanker = new(form.SelectedTanker); - if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + tanker != -1)) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } diff --git a/GasolineTanker/GasolineTanker/TankerDelegate.cs b/GasolineTanker/GasolineTanker/TankerDelegate.cs new file mode 100644 index 0000000..85fe579 --- /dev/null +++ b/GasolineTanker/GasolineTanker/TankerDelegate.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + public delegate void TankerDelegate(DrawningTanker tanker); +}