diff --git a/Battleship/Battleship/FormShipCollection.cs b/Battleship/Battleship/FormShipCollection.cs index cfd8f05..0901969 100644 --- a/Battleship/Battleship/FormShipCollection.cs +++ b/Battleship/Battleship/FormShipCollection.cs @@ -124,10 +124,8 @@ namespace Battleship { return; } - FormBattleship form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - if (obj + form.SelectedShip) + + if (obj + drawningShip) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowShips(); @@ -136,7 +134,7 @@ namespace Battleship { MessageBox.Show("Не удалось добавить объект"); } - } + } private void buttonRemoveShip_Click(object sender, EventArgs e) diff --git a/Battleship/Battleship/FormShipConfig.Designer.cs b/Battleship/Battleship/FormShipConfig.Designer.cs index 43b84ed..3c5dee8 100644 --- a/Battleship/Battleship/FormShipConfig.Designer.cs +++ b/Battleship/Battleship/FormShipConfig.Designer.cs @@ -326,6 +326,7 @@ this.buttonAdd.TabIndex = 13; this.buttonAdd.Text = "Добавить"; this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click_1); // // buttonCancel // diff --git a/Battleship/Battleship/FormShipConfig.cs b/Battleship/Battleship/FormShipConfig.cs index 15b27ec..52a1b27 100644 --- a/Battleship/Battleship/FormShipConfig.cs +++ b/Battleship/Battleship/FormShipConfig.cs @@ -21,7 +21,7 @@ namespace Battleship /// /// Событие /// - private event ShipDelegate? EventAddShip; + public event Action? EventAddShip; /// /// Конструктор /// @@ -56,7 +56,7 @@ namespace Battleship /// Добавление события /// /// Привязанный метод - public void AddEvent(ShipDelegate ev) + public void AddEvent(Action ev) { if (EventAddShip == null) { @@ -119,11 +119,6 @@ namespace Battleship /// /// /// - private void buttonAdd_Click(object sender, EventArgs e) - { - EventAddShip?.Invoke(_ship); - Close(); - } private void PanelColor_MouseDown(object sender, MouseEventArgs e) { @@ -157,6 +152,12 @@ namespace Battleship } DrawShip(); } + + private void buttonAdd_Click_1(object sender, EventArgs e) + { + EventAddShip?.Invoke(_ship); + Close(); + } } } diff --git a/Battleship/Battleship/ShipDelegate.cs b/Battleship/Battleship/ShipDelegate.cs deleted file mode 100644 index ed731ea..0000000 --- a/Battleship/Battleship/ShipDelegate.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Battleship.DrawningObjects; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Battleship -{ - /// - /// Делегат для передачи объекта-автомобиля - /// - /// - public delegate void ShipDelegate(DrawningShip car); -}