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