Генерики

This commit is contained in:
GokaPek 2023-10-10 20:55:27 +04:00
parent 9d409dbed8
commit b22939ef87
7 changed files with 139 additions and 5 deletions

View File

@ -1,6 +1,6 @@
namespace SelfPropelledArtilleryUnit
{
partial class Form
partial class FormSPAU
{
/// <summary>
/// Required designer variable.

View File

@ -4,7 +4,7 @@ using System.Drawing;
namespace SelfPropelledArtilleryUnit
{
public partial class Form : System.Windows.Forms.Form
public partial class FormSPAU : System.Windows.Forms.Form
{
/// <summary>
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
@ -23,7 +23,7 @@ namespace SelfPropelledArtilleryUnit
/// <summary>
/// Èíèöèàëèçàöèÿ ôîðìû
/// </summary>
public Form()
public FormSPAU()
{
InitializeComponent();
_strategy = null;

View File

@ -28,18 +28,82 @@
/// </summary>
private void InitializeComponent()
{
pictureBoxCollection = new PictureBox();
maskedTextBoxNumber = new MaskedTextBox();
ButtonAddSPAU = new Button();
ButtonRemoveSPAU = new Button();
ButtonRefreshCollection = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout();
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(12, 12);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(680, 432);
pictureBoxCollection.TabIndex = 0;
pictureBoxCollection.TabStop = false;
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Location = new Point(729, 51);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(143, 27);
maskedTextBoxNumber.TabIndex = 1;
//
// ButtonAddSPAU
//
ButtonAddSPAU.Location = new Point(748, 102);
ButtonAddSPAU.Name = "ButtonAddSPAU";
ButtonAddSPAU.Size = new Size(102, 33);
ButtonAddSPAU.TabIndex = 2;
ButtonAddSPAU.Text = "Добавить";
ButtonAddSPAU.UseVisualStyleBackColor = true;
ButtonAddSPAU.Click += ButtonAddSPAU_Click;
//
// ButtonRemoveSPAU
//
ButtonRemoveSPAU.Location = new Point(750, 141);
ButtonRemoveSPAU.Name = "ButtonRemoveSPAU";
ButtonRemoveSPAU.Size = new Size(100, 37);
ButtonRemoveSPAU.TabIndex = 3;
ButtonRemoveSPAU.Text = "Удалить";
ButtonRemoveSPAU.UseVisualStyleBackColor = true;
ButtonRemoveSPAU.Click += ButtonRemoveSPAU_Click;
//
// ButtonRefreshCollection
//
ButtonRefreshCollection.Location = new Point(750, 195);
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
ButtonRefreshCollection.Size = new Size(100, 35);
ButtonRefreshCollection.TabIndex = 4;
ButtonRefreshCollection.Text = "Обновить";
ButtonRefreshCollection.UseVisualStyleBackColor = true;
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
//
// FormSPAUCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(899, 456);
Controls.Add(ButtonRefreshCollection);
Controls.Add(ButtonRemoveSPAU);
Controls.Add(ButtonAddSPAU);
Controls.Add(maskedTextBoxNumber);
Controls.Add(pictureBoxCollection);
Name = "FormSPAUCollection";
Text = "FormSPAUCollection";
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private PictureBox pictureBoxCollection;
private MaskedTextBox maskedTextBoxNumber;
private Button ButtonAddSPAU;
private Button ButtonRemoveSPAU;
private Button ButtonRefreshCollection;
}
}

View File

@ -1,4 +1,5 @@
using System;
using SelfPropelledArtilleryUnit.Generics;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -7,14 +8,82 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SelfPropelledArtilleryUnit.DrawningObjects;
using SelfPropelledArtilleryUnit.MovementStrategy;
using SelfPropelledArtilleryUnit.Generics;
namespace SelfPropelledArtilleryUnit
{
/// <summary>
/// Форма для работы с набором объектов класса DrawningSPAU
/// </summary>
public partial class FormSPAUCollection : Form
{
/// <summary>
/// Набор объектов
/// </summary>
private readonly SPAUGenericCollection<DrawningSPAU, DrawningObjectSPAU> _SPAUs;
/// <summary>
/// Конструктор
/// </summary>
public FormSPAUCollection()
{
InitializeComponent();
_SPAUs = new SPAUGenericCollection<DrawningSPAU, DrawningObjectSPAU>(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddSPAU_Click(object sender, EventArgs e)
{
FormSPAU form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_SPAUs + form.SelectedSPAU)
{
MessageBox.Show("Объект добавлен");
//pictureBoxCollection.Image = _SPAUs.ShowSPAUs();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта из набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveSPAU_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_SPAUs - pos != null)
{
MessageBox.Show("Объект удален");
//pictureBoxCollection.Image = _SPAUs.ShowSPAUs();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Обновление рисунка по набору
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefreshCollection_Click(object sender, EventArgs
e)
{
//pictureBoxCollection.Image = _SPAUs.ShowSPAUs();
}
}
}

View File

@ -9,7 +9,8 @@ namespace SelfPropelledArtilleryUnit
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new Form());
Application.Run(new FormSPAUCollection());
//Application.Run(new FormSPAU());
}
}
}