Добавлено событие

This commit is contained in:
Валерия Никифорова 2022-10-27 22:33:44 +04:00
parent 223e3bd5f7
commit 1a1ea1e996
4 changed files with 72 additions and 25 deletions

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AccordionBus
{
/// <summary>
/// Делегат для передачи объекта-автобуса
/// </summary>
/// <param name="bus"></param>
public delegate void BusDelegate(DrawningBus bus);
}

View File

@ -287,7 +287,7 @@
//
this.pictureBoxObject.Location = new System.Drawing.Point(17, 52);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(240, 128);
this.pictureBoxObject.Size = new System.Drawing.Size(308, 128);
this.pictureBoxObject.TabIndex = 1;
this.pictureBoxObject.TabStop = false;
//
@ -299,7 +299,7 @@
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(637, 23);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(276, 197);
this.panelObject.Size = new System.Drawing.Size(342, 197);
this.panelObject.TabIndex = 2;
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
@ -308,7 +308,7 @@
//
this.labelDopColor.AllowDrop = true;
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelDopColor.Location = new System.Drawing.Point(145, 12);
this.labelDopColor.Location = new System.Drawing.Point(183, 12);
this.labelDopColor.Name = "labelDopColor";
this.labelDopColor.Size = new System.Drawing.Size(112, 37);
this.labelDopColor.TabIndex = 10;
@ -320,7 +320,7 @@
//
this.labelBaseColor.AllowDrop = true;
this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelBaseColor.Location = new System.Drawing.Point(17, 12);
this.labelBaseColor.Location = new System.Drawing.Point(44, 12);
this.labelBaseColor.Name = "labelBaseColor";
this.labelBaseColor.Size = new System.Drawing.Size(112, 37);
this.labelBaseColor.TabIndex = 9;
@ -331,16 +331,17 @@
//
// buttonOk
//
this.buttonOk.Location = new System.Drawing.Point(654, 233);
this.buttonOk.Location = new System.Drawing.Point(681, 233);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(112, 29);
this.buttonOk.TabIndex = 3;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(782, 233);
this.buttonCancel.Location = new System.Drawing.Point(820, 233);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(112, 29);
this.buttonCancel.TabIndex = 4;
@ -351,7 +352,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(927, 274);
this.ClientSize = new System.Drawing.Size(991, 274);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.panelObject);

View File

@ -20,6 +20,10 @@ namespace AccordionBus
/// </summary>
DrawningBus _bus = null;
/// <summary>
/// Событие
/// </summary>
private event BusDelegate EventAddBus;
/// <summary>
/// Конструктор
/// </summary>
public FormBusConfig()
@ -46,6 +50,21 @@ namespace AccordionBus
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev"></param>
public void AddEvent(BusDelegate ev)
{
if (EventAddBus == null)
{
EventAddBus = new BusDelegate(ev);
}
else
{
EventAddBus += ev;
}
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
@ -132,5 +151,15 @@ namespace AccordionBus
{
// TODO Call method from object _car if _car is DrawningSportCar and set dop color
}
/// <summary>
/// Добавление автобуса
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddBus?.Invoke(_bus);
Close();
}
}
}

View File

@ -112,24 +112,27 @@ namespace AccordionBus
/// <param name="e"></param>
private void ButtonAddBus_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
FormBus form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectBus bus = new(form.SelectedBus);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + bus != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
var formBusConfig = new FormBusConfig();
// TODO Call method AddEvent from formCarConfig
formBusConfig.Show();
//if (listBoxMaps.SelectedIndex == -1)
//{
// return;
//}
//FormBus form = new();
//if (form.ShowDialog() == DialogResult.OK)
//{
// DrawningObjectBus bus = new(form.SelectedBus);
// if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + bus != -1)
// {
// MessageBox.Show("Объект добавлен");
// pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
// }
// else
// {
// MessageBox.Show("Не удалось добавить объект");
// }
//}
}
/// <summary>
/// Удаление объекта