изменено по использование встроенного делегата

This commit is contained in:
vkobi 2024-04-23 10:39:23 +04:00
parent 0d7e4052f5
commit 6b9a17243f
2 changed files with 6 additions and 4 deletions

View File

@ -44,6 +44,10 @@ public partial class FormLocomotiveCollection : Form
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonAddLocomotive_Click(object sender, EventArgs e) private void ButtonAddLocomotive_Click(object sender, EventArgs e)
{ {
if(_company == null)
{
return;
}
FormLocomotiveConfig form = new(); FormLocomotiveConfig form = new();
// TODO передать метод // TODO передать метод
form.AddEvent(SetLocomotive); form.AddEvent(SetLocomotive);

View File

@ -16,7 +16,7 @@ public partial class FormLocomotiveConfig : Form
/// <summary> /// <summary>
/// Событие для передачи объекта /// Событие для передачи объекта
/// </summary> /// </summary>
private event LocomotiveDelegate? LocomotiveDelegate; private event Action<DrawningLocomotive>? LocomotiveDelegate;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
@ -34,15 +34,13 @@ public partial class FormLocomotiveConfig : Form
panelBlue.MouseDown += Panel_MouseDown; panelBlue.MouseDown += Panel_MouseDown;
buttonCancel.Click += (events, e) => Close(); buttonCancel.Click += (events, e) => Close();
} }
/// <summary> /// <summary>
/// Привязка внешнего метода к событию /// Привязка внешнего метода к событию
/// </summary> /// </summary>
/// <param name="locomotiveDelegate"></param> /// <param name="locomotiveDelegate"></param>
public void AddEvent(LocomotiveDelegate locomotiveDelegate) public void AddEvent(Action<DrawningLocomotive> locomotiveDelegate)
{ {
LocomotiveDelegate += locomotiveDelegate; LocomotiveDelegate += locomotiveDelegate;
} }