Прописана логика формы-коллекции

This commit is contained in:
malimova 2023-12-10 14:44:55 +04:00
parent e08aabd3df
commit 69a0414756
2 changed files with 74 additions and 32 deletions

View File

@ -29,11 +29,11 @@
private void InitializeComponent() private void InitializeComponent()
{ {
groupBoxTools = new GroupBox(); groupBoxTools = new GroupBox();
pictureBoxCollection = new PictureBox();
buttonAddPlane = new Button();
maskedTextBoxNumber = new MaskedTextBox();
buttonRemovePlane = new Button();
buttonRefreshCollection = new Button(); buttonRefreshCollection = new Button();
buttonRemovePlane = new Button();
maskedTextBoxNumber = new MaskedTextBox();
buttonAddPlane = new Button();
pictureBoxCollection = new PictureBox();
groupBoxTools.SuspendLayout(); groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout(); SuspendLayout();
@ -51,23 +51,25 @@
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
// //
// pictureBoxCollection // buttonRefreshCollection
// //
pictureBoxCollection.Dock = DockStyle.Left; buttonRefreshCollection.Location = new Point(17, 357);
pictureBoxCollection.Location = new Point(0, 0); buttonRefreshCollection.Name = "buttonRefreshCollection";
pictureBoxCollection.Name = "pictureBoxCollection"; buttonRefreshCollection.Size = new Size(290, 59);
pictureBoxCollection.Size = new Size(752, 668); buttonRefreshCollection.TabIndex = 3;
pictureBoxCollection.TabIndex = 1; buttonRefreshCollection.Text = "Обновить коллекцию";
pictureBoxCollection.TabStop = false; buttonRefreshCollection.UseVisualStyleBackColor = true;
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
// //
// buttonAddPlane // buttonRemovePlane
// //
buttonAddPlane.Location = new Point(17, 53); buttonRemovePlane.Location = new Point(17, 213);
buttonAddPlane.Name = "buttonAddPlane"; buttonRemovePlane.Name = "buttonRemovePlane";
buttonAddPlane.Size = new Size(290, 59); buttonRemovePlane.Size = new Size(290, 59);
buttonAddPlane.TabIndex = 0; buttonRemovePlane.TabIndex = 2;
buttonAddPlane.Text = "Добавить самолет"; buttonRemovePlane.Text = "Удалить самолет";
buttonAddPlane.UseVisualStyleBackColor = true; buttonRemovePlane.UseVisualStyleBackColor = true;
buttonRemovePlane.Click += buttonRemovePlane_Click;
// //
// maskedTextBoxNumber // maskedTextBoxNumber
// //
@ -78,23 +80,24 @@
maskedTextBoxNumber.TabIndex = 1; maskedTextBoxNumber.TabIndex = 1;
maskedTextBoxNumber.ValidatingType = typeof(int); maskedTextBoxNumber.ValidatingType = typeof(int);
// //
// buttonRemovePlane // buttonAddPlane
// //
buttonRemovePlane.Location = new Point(17, 213); buttonAddPlane.Location = new Point(17, 53);
buttonRemovePlane.Name = "buttonRemovePlane"; buttonAddPlane.Name = "buttonAddPlane";
buttonRemovePlane.Size = new Size(290, 59); buttonAddPlane.Size = new Size(290, 59);
buttonRemovePlane.TabIndex = 2; buttonAddPlane.TabIndex = 0;
buttonRemovePlane.Text = "Удалить самолет"; buttonAddPlane.Text = "Добавить самолет";
buttonRemovePlane.UseVisualStyleBackColor = true; buttonAddPlane.UseVisualStyleBackColor = true;
buttonAddPlane.Click += buttonAddPlane_Click;
// //
// buttonRefreshCollection // pictureBoxCollection
// //
buttonRefreshCollection.Location = new Point(17, 357); pictureBoxCollection.Dock = DockStyle.Left;
buttonRefreshCollection.Name = "buttonRefreshCollection"; pictureBoxCollection.Location = new Point(0, 0);
buttonRefreshCollection.Size = new Size(290, 59); pictureBoxCollection.Name = "pictureBoxCollection";
buttonRefreshCollection.TabIndex = 3; pictureBoxCollection.Size = new Size(752, 668);
buttonRefreshCollection.Text = "Обновить коллекцию"; pictureBoxCollection.TabIndex = 1;
buttonRefreshCollection.UseVisualStyleBackColor = true; pictureBoxCollection.TabStop = false;
// //
// FormPlaneCollection // FormPlaneCollection
// //

View File

@ -12,9 +12,48 @@ namespace AirBomber
{ {
public partial class FormPlaneCollection : Form public partial class FormPlaneCollection : Form
{ {
private readonly PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane> _planes;
public FormPlaneCollection() public FormPlaneCollection()
{ {
InitializeComponent(); InitializeComponent();
_planes = new PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
private void buttonAddPlane_Click(object sender, EventArgs e)
{
FormAirBomber form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_planes + form.SelectedPlane != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _planes.ShowPlanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void buttonRemovePlane_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_planes - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _planes.ShowPlanes();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void buttonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = _planes.ShowPlanes();
} }
} }
} }