Pyatakov K.M. LabWork5 #7

Closed
ker73rus wants to merge 5 commits from LabWork5 into LabWork4
5 changed files with 45 additions and 21 deletions
Showing only changes of commit f3d2973c84 - Show all commits

View File

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
public delegate void AirDelegate(DrawningMilitaryAirplane airplane);
}

View File

@ -334,6 +334,7 @@
this.buttonAdd.TabIndex = 3;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// buttonCancel
//

View File

@ -13,6 +13,7 @@ namespace Stormtrooper
public partial class FormAirConfig : Form
{
DrawningMilitaryAirplane _airplane = null;
private event AirDelegate EventAddAirplane;
public FormAirConfig()
{
InitializeComponent();
@ -24,6 +25,7 @@ namespace Stormtrooper
panelCyan.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (object sender, EventArgs e) => Close();
}
private void DrawAirplane()
@ -34,6 +36,17 @@ namespace Stormtrooper
_airplane?.DrawAirplane(gr);
pictureBoxShow.Image = bmp;
}
public void AddEvent(AirDelegate ev)
{
if (EventAddAirplane == null)
{
EventAddAirplane = new AirDelegate(ev);
}
else
{
EventAddAirplane += ev;
}
}
private void label_MouseDown(object sender, MouseEventArgs e)
{
@ -118,5 +131,11 @@ namespace Stormtrooper
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
EventAddAirplane?.Invoke(_airplane);
Close();
}
}
}

View File

@ -78,32 +78,26 @@ namespace Stormtrooper
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAdd_Click(object sender, EventArgs e)
{
var formLocomotiveConfig = new FormAirConfig();
formLocomotiveConfig.AddEvent(AddLocomotive);
formLocomotiveConfig.Show();
}
private void AddLocomotive(DrawningMilitaryAirplane drawningMilitaryAirplane)
{
if (listBoxMap.SelectedIndex == -1)
{
return;
}
MainForm form = new();
if (form.ShowDialog() == DialogResult.OK)
DrawningObject airplane = new(drawningMilitaryAirplane);
if (_mapCollection[listBoxMap.SelectedItem?.ToString() ?? string.Empty] + airplane != -1)
{
if(form.SelectedAirplane != null)
{
DrawningObject airplane = new (form.SelectedAirplane);
if (_mapCollection[listBoxMap.SelectedItem?.ToString() ?? string.Empty] + airplane != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapCollection[listBoxMap.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
else
{
MessageBox.Show("Объект не создан");
}
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapCollection[listBoxMap.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>

View File

@ -16,7 +16,7 @@ namespace Stormtrooper
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormAirConfig());
Application.Run(new FormMapWithSetAirplane());
}
}
}