PIbd-23 Firsov Kirill LabWork 05 #21

Closed
Firsov_Kirill wants to merge 5 commits from Laba5 into Laba4.2
9 changed files with 708 additions and 32 deletions

View File

@ -95,5 +95,10 @@ namespace ProjectTractor.DrawningObjects
}
}
public void ChangeAdditionalColor(Color color)
{
((EntityBulldoser)EntityTractor).AdditionalColor = color;
}
}
}

View File

@ -6,13 +6,11 @@ using System.Threading.Tasks;
using ProjectTractor.Entities;
using ProjectTractor.MovementStrategy;
namespace ProjectTractor.DrawningObjects {
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningTractor
{
namespace ProjectTractor.DrawningObjects {
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningTractor {
/// <summary>
/// Класс-сущность
/// </summary>
@ -41,15 +39,16 @@ namespace ProjectTractor.DrawningObjects {
/// Высота прорисовки автомобиля
/// </summary>
protected readonly int _tractorHeight = 60;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawningTractor(int speed, double weight, Color bodyColor, int
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawningTractor(int speed, double weight, Color bodyColor, int
width, int height)
{
if (width <= _tractorWidth || height <= _tractorHeight)
@ -228,7 +227,22 @@ namespace ProjectTractor.DrawningObjects {
g.DrawRectangle(pen, _startPosX + 60, _startPosY, 10, 20);
g.DrawRectangle(pen, _startPosX, _startPosY, 40, 20);
}
}
public void ChangeColor(Color color)
{
if (EntityTractor == null)
{
return;
}
EntityTractor.BodyColor = color;
}
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
{
_pictureWidth = pictureBoxWidth;
_pictureHeight = pictureBoxHeight;
}
}
}

View File

@ -14,7 +14,7 @@ namespace ProjectTractor.Entities
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; private set; }
public Color AdditionalColor { get; set; }
Review

В классах-сущностях требовалось прописать методы для смены основного и дополнительного цветов

В классах-сущностях требовалось прописать методы для смены основного и дополнительного цветов
/// <summary>
/// Признак (опция) наличия обвеса
/// </summary>

View File

@ -22,7 +22,7 @@ namespace ProjectTractor.Entities
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
public Color BodyColor { get; set; }
Review

В классах-сущностях требовалось прописать методы для смены основного и дополнительного цветов

В классах-сущностях требовалось прописать методы для смены основного и дополнительного цветов
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
@ -39,6 +39,5 @@ namespace ProjectTractor.Entities
Weight = weight;
BodyColor = bodyColor;
}
}
}

View File

@ -73,7 +73,7 @@ namespace ProjectTractor
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ListBoxObjects_SelectedIndexChanged(object sender,
private void listBoxStorages_SelectedIndexChanged(object sender,
EventArgs e)
{
pictureBoxCollection.Image =
@ -102,6 +102,7 @@ namespace ProjectTractor
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddTractor_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
@ -113,19 +114,24 @@ namespace ProjectTractor
{
return;
}
FormTractor form = new();
if (form.ShowDialog() == DialogResult.OK)
FormTractorConfig form = new();
form.Show();
Action<DrawningTractor>? tractorDelegate = new((m) =>
{
if (obj + form.SelectedTractor)
bool isAdditionSuccessful = (obj + m);
if (isAdditionSuccessful)
{
MessageBox.Show("Объект добавлен");
m.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height);
pictureBoxCollection.Image = obj.ShowTractors();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
});
form.AddEvent(tractorDelegate);
}
/// <summary>
@ -180,7 +186,6 @@ namespace ProjectTractor
}
pictureBoxCollection.Image = obj.ShowTractors();
}
private void InitializeComponent()
{
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
@ -204,7 +209,7 @@ namespace ProjectTractor
this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left;
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCollection.Name = "pictureBoxCollection";
this.pictureBoxCollection.Size = new System.Drawing.Size(620, 536);
this.pictureBoxCollection.Size = new System.Drawing.Size(645, 536);
this.pictureBoxCollection.TabIndex = 1;
this.pictureBoxCollection.TabStop = false;
//
@ -215,7 +220,7 @@ namespace ProjectTractor
this.groupBox.Controls.Add(this.ButtonRemoveTractor);
this.groupBox.Controls.Add(this.ButtonAddTractor);
this.groupBox.Controls.Add(this.maskedTextBoxNumber);
this.groupBox.Location = new System.Drawing.Point(626, 12);
this.groupBox.Location = new System.Drawing.Point(651, 14);
this.groupBox.Name = "groupBox";
this.groupBox.Size = new System.Drawing.Size(255, 522);
this.groupBox.TabIndex = 2;
@ -253,6 +258,7 @@ namespace ProjectTractor
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(203, 84);
this.listBoxStorages.TabIndex = 2;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxStorages_SelectedIndexChanged);
//
// ButtonAddObject
//
@ -310,7 +316,7 @@ namespace ProjectTractor
//
// FormTractorCollection
//
this.ClientSize = new System.Drawing.Size(893, 536);
this.ClientSize = new System.Drawing.Size(918, 536);
this.Controls.Add(this.groupBox);
this.Controls.Add(this.pictureBoxCollection);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
@ -338,7 +344,5 @@ namespace ProjectTractor
private Button ButtonAddObject;
private MaskedTextBox textBoxStorageName;
private PictureBox pictureBoxCollection;
}
}

View File

@ -0,0 +1,410 @@
namespace ProjectTractor
{
partial class FormTractorConfig
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBoxConfig = new System.Windows.Forms.GroupBox();
this.labelModifiedObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.panelPurpule = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelGrey = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.checkBoxBlade = new System.Windows.Forms.CheckBox();
this.checkBoxWheelsOrnament = new System.Windows.Forms.CheckBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.labelColor = new System.Windows.Forms.Label();
this.labelAdditionalColor = new System.Windows.Forms.Label();
this.panelObject = new System.Windows.Forms.Panel();
this.groupBoxConfig.SuspendLayout();
this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.panelObject.SuspendLayout();
this.SuspendLayout();
//
// groupBoxConfig
//
this.groupBoxConfig.Controls.Add(this.labelModifiedObject);
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
this.groupBoxConfig.Controls.Add(this.checkBoxBlade);
this.groupBoxConfig.Controls.Add(this.checkBoxWheelsOrnament);
this.groupBoxConfig.Controls.Add(this.label2);
this.groupBoxConfig.Controls.Add(this.label1);
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
this.groupBoxConfig.Location = new System.Drawing.Point(12, 0);
this.groupBoxConfig.Name = "groupBoxConfig";
this.groupBoxConfig.Size = new System.Drawing.Size(585, 256);
this.groupBoxConfig.TabIndex = 0;
this.groupBoxConfig.TabStop = false;
this.groupBoxConfig.Text = "Параметры";
//
// labelModifiedObject
//
this.labelModifiedObject.BackColor = System.Drawing.SystemColors.ButtonHighlight;
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelModifiedObject.Location = new System.Drawing.Point(449, 171);
this.labelModifiedObject.Name = "labelModifiedObject";
this.labelModifiedObject.Size = new System.Drawing.Size(114, 42);
this.labelModifiedObject.TabIndex = 8;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelSimpleObject
//
this.labelSimpleObject.BackColor = System.Drawing.SystemColors.ButtonHighlight;
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(369, 171);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(74, 42);
this.labelSimpleObject.TabIndex = 7;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBoxColors
//
this.groupBoxColors.Controls.Add(this.panelPurpule);
this.groupBoxColors.Controls.Add(this.panelBlack);
this.groupBoxColors.Controls.Add(this.panelGrey);
this.groupBoxColors.Controls.Add(this.panelYellow);
this.groupBoxColors.Controls.Add(this.panelBlue);
this.groupBoxColors.Controls.Add(this.panelWhite);
this.groupBoxColors.Controls.Add(this.panelGreen);
this.groupBoxColors.Controls.Add(this.panelRed);
this.groupBoxColors.Location = new System.Drawing.Point(369, 28);
this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Size = new System.Drawing.Size(194, 120);
this.groupBoxColors.TabIndex = 6;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета";
//
// panelPurpule
//
this.panelPurpule.AllowDrop = true;
this.panelPurpule.BackColor = System.Drawing.Color.Purple;
this.panelPurpule.Location = new System.Drawing.Point(144, 69);
this.panelPurpule.Name = "panelPurpule";
this.panelPurpule.Size = new System.Drawing.Size(40, 40);
this.panelPurpule.TabIndex = 1;
this.panelPurpule.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
this.panelPurpule.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelBlack
//
this.panelBlack.AllowDrop = true;
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(98, 69);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(40, 40);
this.panelBlack.TabIndex = 1;
this.panelBlack.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelGrey
//
this.panelGrey.AllowDrop = true;
this.panelGrey.BackColor = System.Drawing.Color.Silver;
this.panelGrey.Location = new System.Drawing.Point(52, 69);
this.panelGrey.Name = "panelGrey";
this.panelGrey.Size = new System.Drawing.Size(40, 40);
this.panelGrey.TabIndex = 1;
this.panelGrey.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
this.panelGrey.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelYellow
//
this.panelYellow.AllowDrop = true;
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(145, 23);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(40, 40);
this.panelYellow.TabIndex = 1;
this.panelYellow.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelBlue
//
this.panelBlue.AllowDrop = true;
this.panelBlue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
this.panelBlue.Location = new System.Drawing.Point(98, 23);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(40, 40);
this.panelBlue.TabIndex = 1;
this.panelBlue.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelWhite
//
this.panelWhite.AllowDrop = true;
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(6, 69);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(40, 40);
this.panelWhite.TabIndex = 1;
this.panelWhite.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelGreen
//
this.panelGreen.AllowDrop = true;
this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
this.panelGreen.Location = new System.Drawing.Point(52, 23);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(40, 40);
this.panelGreen.TabIndex = 0;
this.panelGreen.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelRed
//
this.panelRed.AllowDrop = true;
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(6, 23);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(40, 40);
this.panelRed.TabIndex = 0;
this.panelRed.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// checkBoxBlade
//
this.checkBoxBlade.AutoSize = true;
this.checkBoxBlade.Location = new System.Drawing.Point(32, 154);
this.checkBoxBlade.Name = "checkBoxBlade";
this.checkBoxBlade.Size = new System.Drawing.Size(205, 24);
this.checkBoxBlade.TabIndex = 5;
this.checkBoxBlade.Text = "Признак наличия отвала";
this.checkBoxBlade.UseVisualStyleBackColor = true;
//
// checkBoxWheelsOrnament
//
this.checkBoxWheelsOrnament.AutoSize = true;
this.checkBoxWheelsOrnament.Location = new System.Drawing.Point(32, 189);
this.checkBoxWheelsOrnament.Name = "checkBoxWheelsOrnament";
this.checkBoxWheelsOrnament.Size = new System.Drawing.Size(305, 24);
this.checkBoxWheelsOrnament.TabIndex = 4;
this.checkBoxWheelsOrnament.Text = "Признак наличия орнамета на колесах";
this.checkBoxWheelsOrnament.UseVisualStyleBackColor = true;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(32, 82);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(33, 20);
this.label2.TabIndex = 3;
this.label2.Text = "Вес";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(32, 28);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(73, 20);
this.label1.TabIndex = 2;
this.label1.Text = "Скорость";
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(132, 80);
this.numericUpDownWeight.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownWeight.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(109, 27);
this.numericUpDownWeight.TabIndex = 1;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(132, 26);
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(109, 27);
this.numericUpDownSpeed.TabIndex = 0;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// buttonOk
//
this.buttonOk.Location = new System.Drawing.Point(631, 227);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(94, 29);
this.buttonOk.TabIndex = 2;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(746, 227);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 3;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(3, 50);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(259, 150);
this.pictureBoxObject.TabIndex = 2;
this.pictureBoxObject.TabStop = false;
//
// labelColor
//
this.labelColor.AllowDrop = true;
this.labelColor.BackColor = System.Drawing.SystemColors.ButtonHighlight;
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelColor.Location = new System.Drawing.Point(2, 15);
this.labelColor.Name = "labelColor";
this.labelColor.Size = new System.Drawing.Size(119, 32);
this.labelColor.TabIndex = 3;
this.labelColor.Text = "Цвет";
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
//
// labelAdditionalColor
//
this.labelAdditionalColor.AllowDrop = true;
this.labelAdditionalColor.BackColor = System.Drawing.SystemColors.ButtonHighlight;
this.labelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelAdditionalColor.Location = new System.Drawing.Point(142, 15);
this.labelAdditionalColor.Name = "labelAdditionalColor";
this.labelAdditionalColor.Size = new System.Drawing.Size(120, 32);
this.labelAdditionalColor.TabIndex = 4;
this.labelAdditionalColor.Text = "Доп. цвет";
this.labelAdditionalColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelAdditionalColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAdditionalColor_DragDrop);
this.labelAdditionalColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelObject.Controls.Add(this.labelAdditionalColor);
this.panelObject.Controls.Add(this.labelColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(603, 12);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(267, 208);
this.panelObject.TabIndex = 4;
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelObject_DragEnter);
//
// FormTractorConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(882, 271);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.groupBoxConfig);
this.Name = "FormTractorConfig";
this.Text = "FormTractorConfig";
this.groupBoxConfig.ResumeLayout(false);
this.groupBoxConfig.PerformLayout();
this.groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.panelObject.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private GroupBox groupBoxColors;
private Panel panelRed;
private Panel panelGreen;
private CheckBox checkBoxBlade;
private CheckBox checkBoxWheelsOrnament;
private Label label2;
private Label label1;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Panel panelPurpule;
private Panel panelBlack;
private Panel panelGrey;
private Panel panelYellow;
private Panel panelBlue;
private Panel panelWhite;
private Label labelModifiedObject;
private Label labelSimpleObject;
private Button buttonOk;
private Button buttonCancel;
private PictureBox pictureBoxObject;
private Label labelColor;
private Label labelAdditionalColor;
private Panel panelObject;
}
}

View File

@ -0,0 +1,184 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectTractor.DrawningObjects;
using ProjectTractor.Entities;
using ProjectTractor.Generics;
using ProjectTractor.MovementStrategy;
namespace ProjectTractor;
public partial class FormTractorConfig : Form
{
/// <summary>
/// Переменная-выбранный трактор
/// </summary>
DrawningTractor? _tractor = null;
/// <summary>
/// Событие
/// </summary>
private event Action<DrawningTractor>? EventAddTractor;
/// <summary>
/// Конструктор
/// </summary>
//
public delegate void TractorDelegate(DrawningTractor tractor);
Review

Делегат следовало заменить на встроенный

Делегат следовало заменить на встроенный
public FormTractorConfig()
{
InitializeComponent();
panelBlack.MouseDown += panelColor_MouseDown;
panelPurpule.MouseDown += panelColor_MouseDown;
panelGrey.MouseDown += panelColor_MouseDown;
panelGreen.MouseDown += panelColor_MouseDown;
panelRed.MouseDown += panelColor_MouseDown;
panelWhite.MouseDown += panelColor_MouseDown;
panelYellow.MouseDown += panelColor_MouseDown;
panelBlue.MouseDown += panelColor_MouseDown;
labelSimpleObject.MouseDown += LabelObject_MouseDown;
labelModifiedObject.MouseDown += LabelObject_MouseDown;
buttonCancel.Click += (s, e) => Close();
}
/// <summary>
/// Отрисовать трактор
/// </summary>
private void DrawTractor()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_tractor?.SetPosition(5, 5);
_tractor?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
public void AddEvent(Action<DrawningTractor> ev)
{
if (EventAddTractor == null)
{
EventAddTractor = ev;
}
else
{
EventAddTractor += ev;
}
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_tractor = new DrawningTractor((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
case "labelModifiedObject":
_tractor = new DrawningBulldoser((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxWheelsOrnament.Checked,
checkBoxBlade.Checked, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
}
labelColor.BackColor = Color.Empty;
labelAdditionalColor.BackColor = Color.Empty;
DrawTractor();
}
/// <summary>
/// Смена цвета
/// </summary>
private void panelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void labelColor_DragDrop(object sender, DragEventArgs e)
{
if (_tractor == null)
{
return;
}
labelColor.BackColor = (Color)e.Data.GetData(typeof(Color));
_tractor.ChangeColor(labelColor.BackColor);
DrawTractor();
}
private void labelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
if ((_tractor == null) || (_tractor is DrawningBulldoser == false))
{
return;
}
labelAdditionalColor.BackColor = (Color)e.Data.GetData(typeof(Color));
((DrawningBulldoser)_tractor).ChangeAdditionalColor(labelAdditionalColor.BackColor);
DrawTractor();
}
/// <summary>
/// Добавление трактора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
///
private void ButtonOk_Click(object sender, EventArgs e)
{
if (_tractor == null)
return;
EventAddTractor?.Invoke(_tractor);
Close();
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -134,7 +134,7 @@ namespace ProjectTractor.Generics
if (tractor != null)
{
int countRows = _pictureWidth / _placeSizeWidth;
tractor.SetPosition(_pictureWidth - _placeSizeWidth * 2 - (i % countRows * _placeSizeWidth) + 20, _pictureHeight - i / countRows * _placeSizeHeight - 160);
tractor.SetPosition(_pictureWidth - _placeSizeWidth - (i % countRows * _placeSizeWidth), _pictureHeight - i / countRows * _placeSizeHeight - 160);
tractor.DrawTransport(g);
}
i++;