Event work
This commit is contained in:
parent
5c3ed88317
commit
d3d75cc1e3
@ -17,6 +17,10 @@ namespace AirFighter
|
||||
/// </summary>
|
||||
DrawningAirFighter _airFighter = null;
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
private event Action<DrawningAirFighter> EventAddAirFighter;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormAirFighterConfig()
|
||||
@ -30,6 +34,8 @@ namespace AirFighter
|
||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
// Закрытие формы
|
||||
buttonCancel.Click += (object sender, EventArgs e) => this.Close();
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовать объект
|
||||
@ -43,6 +49,21 @@ namespace AirFighter
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="ev"></param>
|
||||
public void AddEvent(Action<DrawningAirFighter> ev)
|
||||
{
|
||||
if (EventAddAirFighter == null)
|
||||
{
|
||||
EventAddAirFighter = new Action<DrawningAirFighter>(ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddAirFighter += ev;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Передаем информацию при нажатии на Label
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
@ -143,5 +164,15 @@ namespace AirFighter
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление самолета
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonOk_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddAirFighter?.Invoke(_airFighter);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,21 +59,15 @@ namespace AirFighter
|
||||
listBoxMaps.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddAirFighter_Click(object sender, EventArgs e)
|
||||
void AddAirFighter(DrawningAirFighter _airFighter)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormAirFighter form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
if (_airFighter != null)
|
||||
{
|
||||
DrawningObjectAirFighter airFighter = new(form.SelectedAirFighter);
|
||||
DrawningObjectAirFighter airFighter = new(_airFighter);
|
||||
if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airFighter) == 0)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
@ -86,6 +80,19 @@ namespace AirFighter
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddAirFighter_Click(object sender, EventArgs e)
|
||||
{
|
||||
var formAirFighterConfig = new FormAirFighterConfig();
|
||||
Action<DrawningAirFighter> airFighterDelegate;
|
||||
airFighterDelegate = new(AddAirFighter);
|
||||
formAirFighterConfig.AddEvent(airFighterDelegate);
|
||||
formAirFighterConfig.Show();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
|
Loading…
Reference in New Issue
Block a user