From 18aa8f88dcb20a65ce26082899671fc7c9429802 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 20 Oct 2022 11:35:08 +0400 Subject: [PATCH] Event. --- Airbus/Airbus/FormMapWithSetPlanes.cs | 26 ++++++++++++++------- Airbus/Airbus/FormPlaneConfig.Designer.cs | 2 ++ Airbus/Airbus/FormPlaneConfig.cs | 28 +++++++++++++++++++++++ Airbus/Airbus/PlaneDelegate.cs | 5 ++++ 4 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 Airbus/Airbus/PlaneDelegate.cs diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index b411b67..69dc45f 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -103,18 +103,27 @@ namespace Airbus //добавление объекта private void ButtonAddPlane_Click(object sender, EventArgs e) { - if(_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] == null) + var formPlaneConfig = new FormPlaneConfig(); + + //TODO Call method AvvEvent from formPlaneConfig + + formPlaneConfig.Show(); + + ////////////// ЭТО + /*if(_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] == null) { return; - } - - Form1 form = new(); + }*/ + ////////////// + + /*Form1 form = new(); if(form.ShowDialog() == DialogResult.OK) { - DrawningObjectPlane plane = new(form.SelectedPlane); + DrawningObjectPlane plane = new(form.SelectedPlane);*/ - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] + plane != -1) + /////////////////// И ЭТО В ОТДЕЛЬНЫЙ МЕТОД + /*if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] + plane != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet(); @@ -122,8 +131,9 @@ namespace Airbus else { MessageBox.Show("Не удалось добавить объект"); - } - } + }*/ + ////////////////// + //} } //удаление объекта diff --git a/Airbus/Airbus/FormPlaneConfig.Designer.cs b/Airbus/Airbus/FormPlaneConfig.Designer.cs index 9d8717e..7dd58f1 100644 --- a/Airbus/Airbus/FormPlaneConfig.Designer.cs +++ b/Airbus/Airbus/FormPlaneConfig.Designer.cs @@ -305,6 +305,7 @@ this.buttonAddObject.TabIndex = 3; this.buttonAddObject.Text = "Добавить"; this.buttonAddObject.UseVisualStyleBackColor = true; + this.buttonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click); // // buttonCancel // @@ -314,6 +315,7 @@ this.buttonCancel.TabIndex = 4; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // // FormPlaneConfig // diff --git a/Airbus/Airbus/FormPlaneConfig.cs b/Airbus/Airbus/FormPlaneConfig.cs index 782f697..0ddae29 100644 --- a/Airbus/Airbus/FormPlaneConfig.cs +++ b/Airbus/Airbus/FormPlaneConfig.cs @@ -15,6 +15,9 @@ namespace Airbus //переменная-выбранная машина DrawningAirbus _plane = null; + //событие + private event PlaneDelegate EventAddPlane; + //конструктор public FormPlaneConfig() { @@ -29,6 +32,7 @@ namespace Airbus panelBlue.MouseDown += PanelColor_MouseDown; } + //отрисовка самолёт private void DrawPlane() { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); @@ -38,6 +42,19 @@ namespace Airbus pictureBoxObject.Image = bmp; } + //добавление события + public void AddEvent(PlaneDelegate ev) + { + if(EventAddPlane == null) + { + EventAddPlane = new PlaneDelegate(ev); + } + else + { + EventAddPlane += ev; + } + } + private void LabelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy); @@ -104,5 +121,16 @@ namespace Airbus //TODO Call method from object _plane is DrawningSuperAirbus and set add color } + //добавление машины + private void ButtonAddObject_Click(object sender, EventArgs e) + { + EventAddPlane?.Invoke(_plane); + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } } } diff --git a/Airbus/Airbus/PlaneDelegate.cs b/Airbus/Airbus/PlaneDelegate.cs new file mode 100644 index 0000000..1ceb27d --- /dev/null +++ b/Airbus/Airbus/PlaneDelegate.cs @@ -0,0 +1,5 @@ +namespace Airbus +{ + //делегат для передачи объекта-самолёта + public delegate void PlaneDelegate(DrawningAirbus plane); +}