diff --git a/AirBomber/AirBomber/AirBomberDelegate.cs b/AirBomber/AirBomber/AirBomberDelegate.cs new file mode 100644 index 0000000..0af60c7 --- /dev/null +++ b/AirBomber/AirBomber/AirBomberDelegate.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public delegate void AirBomberDelegate(DrawningBomber airBomber); +} diff --git a/AirBomber/AirBomber/FormAirBomberConfig.Designer.cs b/AirBomber/AirBomber/FormAirBomberConfig.Designer.cs index b1b1564..07d65f7 100644 --- a/AirBomber/AirBomber/FormAirBomberConfig.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomberConfig.Designer.cs @@ -50,7 +50,7 @@ this.panelObject = new System.Windows.Forms.Panel(); this.labelDopColor = new System.Windows.Forms.Label(); this.labelBaseColor = new System.Windows.Forms.Label(); - this.button1 = new System.Windows.Forms.Button(); + this.buttonOk = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.groupBoxConfig.SuspendLayout(); this.groupBoxColors.SuspendLayout(); @@ -286,14 +286,15 @@ this.labelBaseColor.Text = "Цвет"; this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // button1 + // buttonOk // - this.button1.Location = new System.Drawing.Point(777, 226); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(105, 38); - this.button1.TabIndex = 3; - this.button1.Text = "Добавить"; - this.button1.UseVisualStyleBackColor = true; + this.buttonOk.Location = new System.Drawing.Point(777, 226); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(105, 38); + this.buttonOk.TabIndex = 3; + this.buttonOk.Text = "Добавить"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click); // // button2 // @@ -310,7 +311,7 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1055, 279); this.Controls.Add(this.button2); - this.Controls.Add(this.button1); + this.Controls.Add(this.buttonOk); this.Controls.Add(this.panelObject); this.Controls.Add(this.groupBoxConfig); this.Name = "FormAirBomberConfig"; @@ -350,7 +351,7 @@ private Panel panelObject; private Label labelDopColor; private Label labelBaseColor; - private Button button1; + private Button buttonOk; private Button button2; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAirBomberConfig.cs b/AirBomber/AirBomber/FormAirBomberConfig.cs index b187451..eea585a 100644 --- a/AirBomber/AirBomber/FormAirBomberConfig.cs +++ b/AirBomber/AirBomber/FormAirBomberConfig.cs @@ -13,6 +13,8 @@ namespace AirBomber public partial class FormAirBomberConfig : Form { DrawningBomber _airBomber = null; + + private event AirBomberDelegate EventAddAirBomber; public FormAirBomberConfig() { InitializeComponent(); @@ -24,6 +26,8 @@ namespace AirBomber panelRed.MouseDown += PanelColor_MouseDown; panelPurple.MouseDown += PanelColor_MouseDown; panelGreen.MouseDown += PanelColor_MouseDown; + + // TODO buttonCancel.Click with lambda } private void DrawAirBomber() @@ -35,6 +39,18 @@ namespace AirBomber pictureBoxObject.Image = bmp; } + public void AddEvent(AirBomberDelegate ev) + { + if (EventAddAirBomber == null) + { + EventAddAirBomber = new AirBomberDelegate(ev); + } + else + { + EventAddAirBomber += ev; + } + } + private void LabelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy); @@ -76,7 +92,7 @@ namespace AirBomber private void PanelColor_MouseDown(object sender, MouseEventArgs e) { - (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move |) + (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); } private void PanelObject_DragDrop(object sender, DragEventArgs e) @@ -93,5 +109,11 @@ namespace AirBomber } DrawAirBomber(); } + + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddAirBomber?.Invoke(_airBomber); + Close(); + } } } diff --git a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs index d2b9515..82af5df 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs @@ -56,24 +56,9 @@ namespace AirBomber private void ButtonAddAirBomber_Click(object sender, EventArgs e) { - if (listBoxMaps.SelectedIndex == -1) - { - return; - } - FormAirBomber form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - DrawningObjectBomber airBomber = new(form.SelectedAirBomber); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airBomber > -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } + var formAirBomberConfig = new FormAirBomberConfig(); + // TODO Call method AddEvent form formCarConfig + formAirBomberConfig.Show(); } private void ButtonRemoveAirBomber_Click(object sender, EventArgs e)