diff --git a/Stormtrooper/Stormtrooper/AirDelegate.cs b/Stormtrooper/Stormtrooper/AirDelegate.cs
new file mode 100644
index 0000000..70d2a59
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/AirDelegate.cs
@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Stormtrooper
+{
+ public delegate void AirDelegate(DrawningMilitaryAirplane airplane);
+}
diff --git a/Stormtrooper/Stormtrooper/FormAirConfig.Designer.cs b/Stormtrooper/Stormtrooper/FormAirConfig.Designer.cs
index a825a9b..d412a15 100644
--- a/Stormtrooper/Stormtrooper/FormAirConfig.Designer.cs
+++ b/Stormtrooper/Stormtrooper/FormAirConfig.Designer.cs
@@ -334,6 +334,7 @@
this.buttonAdd.TabIndex = 3;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// buttonCancel
//
diff --git a/Stormtrooper/Stormtrooper/FormAirConfig.cs b/Stormtrooper/Stormtrooper/FormAirConfig.cs
index 0ee2496..1ae0ff9 100644
--- a/Stormtrooper/Stormtrooper/FormAirConfig.cs
+++ b/Stormtrooper/Stormtrooper/FormAirConfig.cs
@@ -13,6 +13,7 @@ namespace Stormtrooper
public partial class FormAirConfig : Form
{
DrawningMilitaryAirplane _airplane = null;
+ private event AirDelegate EventAddAirplane;
public FormAirConfig()
{
InitializeComponent();
@@ -24,6 +25,7 @@ namespace Stormtrooper
panelCyan.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
+ buttonCancel.Click += (object sender, EventArgs e) => Close();
}
private void DrawAirplane()
@@ -34,6 +36,17 @@ namespace Stormtrooper
_airplane?.DrawAirplane(gr);
pictureBoxShow.Image = bmp;
}
+ public void AddEvent(AirDelegate ev)
+ {
+ if (EventAddAirplane == null)
+ {
+ EventAddAirplane = new AirDelegate(ev);
+ }
+ else
+ {
+ EventAddAirplane += ev;
+ }
+ }
private void label_MouseDown(object sender, MouseEventArgs e)
{
@@ -118,5 +131,11 @@ namespace Stormtrooper
}
}
+
+ private void buttonAdd_Click(object sender, EventArgs e)
+ {
+ EventAddAirplane?.Invoke(_airplane);
+ Close();
+ }
}
}
diff --git a/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.cs b/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.cs
index e19fd65..8dc221b 100644
--- a/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.cs
+++ b/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.cs
@@ -78,32 +78,26 @@ namespace Stormtrooper
///
///
private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var formLocomotiveConfig = new FormAirConfig();
+ formLocomotiveConfig.AddEvent(AddLocomotive);
+ formLocomotiveConfig.Show();
+ }
+ private void AddLocomotive(DrawningMilitaryAirplane drawningMilitaryAirplane)
{
if (listBoxMap.SelectedIndex == -1)
{
return;
}
- MainForm form = new();
- if (form.ShowDialog() == DialogResult.OK)
+ DrawningObject airplane = new(drawningMilitaryAirplane);
+ if (_mapCollection[listBoxMap.SelectedItem?.ToString() ?? string.Empty] + airplane != -1)
{
- if(form.SelectedAirplane != null)
- {
- DrawningObject airplane = new (form.SelectedAirplane);
- if (_mapCollection[listBoxMap.SelectedItem?.ToString() ?? string.Empty] + airplane != -1)
- {
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _mapCollection[listBoxMap.SelectedItem?.ToString() ?? string.Empty].ShowSet();
- }
- else
- {
- MessageBox.Show("Не удалось добавить объект");
- }
- }
- else
- {
- MessageBox.Show("Объект не создан");
- }
-
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapCollection[listBoxMap.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
}
}
///
diff --git a/Stormtrooper/Stormtrooper/Program.cs b/Stormtrooper/Stormtrooper/Program.cs
index f6676cc..65b5334 100644
--- a/Stormtrooper/Stormtrooper/Program.cs
+++ b/Stormtrooper/Stormtrooper/Program.cs
@@ -16,7 +16,7 @@ namespace Stormtrooper
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new FormAirConfig());
+ Application.Run(new FormMapWithSetAirplane());
}
}
}