Event work

This commit is contained in:
Володя 2022-11-19 17:36:49 +03:00
parent cde98ea4e6
commit ab9fdf006d
3 changed files with 29 additions and 23 deletions

View File

@ -86,26 +86,8 @@ namespace AirPlaneWithRadar
private void ButtonAddPlain_Click(object sender, EventArgs e) private void ButtonAddPlain_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1) var formPlainConfig = new FormPlaneConfig();
{ formPlainConfig.Show();
return;
}
FormPlain form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectPlane plain = new(form.SelectedPlain);
if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + plain) >= 0)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
} }
private void ButtonRemovePlain_Click(object sender, EventArgs e) private void ButtonRemovePlain_Click(object sender, EventArgs e)
{ {

View File

@ -14,7 +14,7 @@ namespace AirPlaneWithRadar
{ {
DrawingPlain _Plane = null; DrawingPlain _Plane = null;
private event PlainDelegate EventAddPlane;
public FormPlaneConfig() public FormPlaneConfig()
{ {
@ -40,7 +40,17 @@ namespace AirPlaneWithRadar
pictureBoxObject.Image = bmp; pictureBoxObject.Image = bmp;
} }
public void AddEvent(PlainDelegate ev)
{
if (EventAddPlane == null)
{
EventAddPlane = ev;
}
else
{
EventAddPlane += ev;
}
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e) private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{ {
@ -119,7 +129,11 @@ namespace AirPlaneWithRadar
} }
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddPlane?.Invoke(_Plane);
Close();
}
} }
} }

View File

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirPlaneWithRadar
{
public delegate void PlainDelegate(DrawingPlain car);
}