101 lines
3.3 KiB
C#
101 lines
3.3 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Reflection.Metadata.Ecma335;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using Cruiser.Drawing;
|
||
using Cruiser.Generics;
|
||
using Cruiser.MovementStrategy;
|
||
|
||
namespace Cruiser
|
||
{
|
||
/// <summary>
|
||
/// Форма для работы с набором объектов класса DrawingCruiser
|
||
/// </summary>
|
||
public partial class FormCruiserCollection : Form
|
||
{
|
||
/// <summary>
|
||
/// Набор объектов
|
||
/// </summary>
|
||
private readonly CarsGenericCollection<DrawingCruiser, DrawningObjectCar> _cruisers;
|
||
/// <summary>
|
||
/// Конструктор
|
||
/// </summary>
|
||
public FormCruiserCollection()
|
||
{
|
||
InitializeComponent();
|
||
_cruisers = new CarsGenericCollection<DrawingCruiser, DrawningObjectCar>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||
}
|
||
/// <summary>
|
||
/// Добавление объекта в набор
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void buttonAddCruiser_Click(object sender, EventArgs e)
|
||
{
|
||
FormCruiser form = new();
|
||
if (form.ShowDialog() == DialogResult.OK)
|
||
{
|
||
if (_cruisers + form.SelectedCruiser != -1)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
pictureBoxCollection.Image = _cruisers.ShowCruiser();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Удаление объекта из набора
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
||
{
|
||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||
{
|
||
return;
|
||
}
|
||
if (textBoxNumber.Text == "")
|
||
{
|
||
MessageBox.Show("Вы ничего не ввели");
|
||
return;
|
||
}
|
||
int pos = Convert.ToInt32(textBoxNumber.Text);
|
||
if (_cruisers - pos)
|
||
{
|
||
MessageBox.Show("Объект удален");
|
||
pictureBoxCollection.Image = _cruisers.ShowCruiser();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось удалить объект");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Обновление рисунка по набору
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||
{
|
||
pictureBoxCollection.Image = _cruisers.ShowCruiser();
|
||
}
|
||
|
||
|
||
|
||
private void FormCruiserCollection_Load(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|