Пятая лабораторая работа. Работа с event
This commit is contained in:
parent
f88b41849d
commit
8463082f80
@ -80,6 +80,7 @@
|
||||
this.buttonOk.TabIndex = 8;
|
||||
this.buttonOk.Text = "Добавить";
|
||||
this.buttonOk.UseVisualStyleBackColor = true;
|
||||
this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
|
||||
//
|
||||
// panelObject
|
||||
//
|
||||
|
@ -14,6 +14,8 @@ namespace AirBomber
|
||||
{
|
||||
DrawingAirBomber _airBomber = null;
|
||||
|
||||
private event Action<DrawingAirBomber> EventAddAirBomber;
|
||||
|
||||
public FormAirBomberConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -25,6 +27,7 @@ namespace AirBomber
|
||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
buttonCancel.Click += (object sender, EventArgs e) => Close();
|
||||
}
|
||||
|
||||
private void DrawAirBomber()
|
||||
@ -53,6 +56,18 @@ namespace AirBomber
|
||||
}
|
||||
}
|
||||
|
||||
public void AddEvent(Action<DrawingAirBomber> ev)
|
||||
{
|
||||
if (EventAddAirBomber == null)
|
||||
{
|
||||
EventAddAirBomber = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddAirBomber += ev;
|
||||
}
|
||||
}
|
||||
|
||||
private void panelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data.GetData(DataFormats.Text).ToString())
|
||||
@ -75,7 +90,7 @@ namespace AirBomber
|
||||
|
||||
private void labelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
if (e.Data.GetDataPresent(typeof(String)))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
@ -88,6 +103,7 @@ namespace AirBomber
|
||||
private void labelBaseColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
_airBomber?.AirBomber?.setColor(Color.FromName(e.Data.GetData(DataFormats.Text).ToString()));
|
||||
DrawAirBomber();
|
||||
}
|
||||
|
||||
private void labelDopColor_DragDrop(object sender, DragEventArgs e)
|
||||
@ -95,7 +111,14 @@ namespace AirBomber
|
||||
if (_airBomber.AirBomber is EntityHeavyAirBomber heavyAirBomber)
|
||||
{
|
||||
heavyAirBomber.setDopColor(Color.FromName(e.Data.GetData(DataFormats.Text).ToString()));
|
||||
}
|
||||
DrawAirBomber();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonOk_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddAirBomber?.Invoke(_airBomber);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,10 @@ namespace AirBomber
|
||||
/// </summary>
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
|
||||
private Action<DrawingAirBomber> AddAction;
|
||||
|
||||
private DrawingObjectAirBomber returnedAirBomber;
|
||||
|
||||
public FormMapWithSetAirBombers()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -36,6 +40,8 @@ namespace AirBomber
|
||||
{
|
||||
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||
}
|
||||
AddAction = airBomber => { _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].add(new DrawingObjectAirBomber(airBomber));
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();};
|
||||
}
|
||||
|
||||
private void buttonAddAirBomber_Click(object sender, EventArgs e)
|
||||
@ -44,20 +50,9 @@ namespace AirBomber
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormAirBomber form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawingObjectAirBomber airBomber = new(form.SelectedAirBomber);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airBomber != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
var formAirBomberConfig = new FormAirBomberConfig();
|
||||
formAirBomberConfig.AddEvent(AddAction);
|
||||
formAirBomberConfig.Show();
|
||||
}
|
||||
|
||||
private void buttonRemoveAirBomber_Click(object sender, EventArgs e)
|
||||
|
@ -69,6 +69,11 @@ namespace AirBomber
|
||||
{
|
||||
return map._setAirBombers.Remove(position);
|
||||
}
|
||||
|
||||
public void add(T airBomber)
|
||||
{
|
||||
_setAirBombers.Insert(airBomber);
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user