diff --git a/ElectricLocomotive/Entities/EntityElectricLocomotive.cs b/ElectricLocomotive/Entities/EntityElectricLocomotive.cs
index fb7cb99..c8bdf72 100644
--- a/ElectricLocomotive/Entities/EntityElectricLocomotive.cs
+++ b/ElectricLocomotive/Entities/EntityElectricLocomotive.cs
@@ -42,5 +42,9 @@ namespace ProjectElectricLocomotive.Entities
Battery = battery;
}
+ public void ChangeAdditionalColor(Color additionalColor)
+ {
+ AdditionalColor = additionalColor;
+ }
}
}
diff --git a/ElectricLocomotive/Entities/EntityLocomotive.cs b/ElectricLocomotive/Entities/EntityLocomotive.cs
index f115bac..becb8e7 100644
--- a/ElectricLocomotive/Entities/EntityLocomotive.cs
+++ b/ElectricLocomotive/Entities/EntityLocomotive.cs
@@ -42,5 +42,10 @@ namespace ProjectElectricLocomotive.Entities
Weight = weight;
BodyColor = bodyColor;
}
+
+ public void ChangeBodyColor(Color color)
+ {
+ BodyColor = color;
+ }
}
}
diff --git a/ElectricLocomotive/FormLocomotiveConfig.Designer.cs b/ElectricLocomotive/FormLocomotiveConfig.Designer.cs
new file mode 100644
index 0000000..02093e8
--- /dev/null
+++ b/ElectricLocomotive/FormLocomotiveConfig.Designer.cs
@@ -0,0 +1,364 @@
+namespace ProjectElectricLocomotive
+{
+ partial class FormLocomotiveConfig
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ groupBox1 = new GroupBox();
+ labelModifiedObject = new Label();
+ labelSimpleObject = new Label();
+ groupBox2 = new GroupBox();
+ panelPurple = new Panel();
+ panelBlack = new Panel();
+ panelGray = new Panel();
+ panelWhite = new Panel();
+ panelYellow = new Panel();
+ panelBlue = new Panel();
+ panelGreen = new Panel();
+ panelRed = new Panel();
+ checkBoxBattery = new CheckBox();
+ checkBoxHorns = new CheckBox();
+ numericUpDownWeight = new NumericUpDown();
+ numericUpDownSpeed = new NumericUpDown();
+ label2 = new Label();
+ label1 = new Label();
+ pictureBoxObject = new PictureBox();
+ labelBodyColor = new Label();
+ labelAdditionalColor = new Label();
+ buttonOK = new Button();
+ buttonClose = new Button();
+ panelObject = new Panel();
+ groupBox1.SuspendLayout();
+ groupBox2.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
+ panelObject.SuspendLayout();
+ SuspendLayout();
+ //
+ // groupBox1
+ //
+ groupBox1.Controls.Add(labelModifiedObject);
+ groupBox1.Controls.Add(labelSimpleObject);
+ groupBox1.Controls.Add(groupBox2);
+ groupBox1.Controls.Add(checkBoxBattery);
+ groupBox1.Controls.Add(checkBoxHorns);
+ groupBox1.Controls.Add(numericUpDownWeight);
+ groupBox1.Controls.Add(numericUpDownSpeed);
+ groupBox1.Controls.Add(label2);
+ groupBox1.Controls.Add(label1);
+ groupBox1.Location = new Point(12, 31);
+ groupBox1.Name = "groupBox1";
+ groupBox1.Size = new Size(568, 293);
+ groupBox1.TabIndex = 0;
+ groupBox1.TabStop = false;
+ groupBox1.Text = "Параметры";
+ //
+ // labelModifiedObject
+ //
+ labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
+ labelModifiedObject.Location = new Point(397, 219);
+ labelModifiedObject.Name = "labelModifiedObject";
+ labelModifiedObject.Size = new Size(113, 35);
+ labelModifiedObject.TabIndex = 8;
+ labelModifiedObject.Text = "Продвинутый";
+ labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
+ labelModifiedObject.MouseDown += labelObject_MouseDown;
+ //
+ // labelSimpleObject
+ //
+ labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
+ labelSimpleObject.Location = new Point(278, 219);
+ labelSimpleObject.Name = "labelSimpleObject";
+ labelSimpleObject.Size = new Size(113, 35);
+ labelSimpleObject.TabIndex = 7;
+ labelSimpleObject.Text = "Простой";
+ labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
+ labelSimpleObject.MouseDown += labelObject_MouseDown;
+ //
+ // groupBox2
+ //
+ groupBox2.Controls.Add(panelPurple);
+ groupBox2.Controls.Add(panelBlack);
+ groupBox2.Controls.Add(panelGray);
+ groupBox2.Controls.Add(panelWhite);
+ groupBox2.Controls.Add(panelYellow);
+ groupBox2.Controls.Add(panelBlue);
+ groupBox2.Controls.Add(panelGreen);
+ groupBox2.Controls.Add(panelRed);
+ groupBox2.Location = new Point(278, 57);
+ groupBox2.Name = "groupBox2";
+ groupBox2.Size = new Size(239, 135);
+ groupBox2.TabIndex = 6;
+ groupBox2.TabStop = false;
+ groupBox2.Text = "Цвета";
+ //
+ // panelPurple
+ //
+ panelPurple.BackColor = Color.Purple;
+ panelPurple.Location = new Point(184, 81);
+ panelPurple.Name = "panelPurple";
+ panelPurple.Size = new Size(40, 40);
+ panelPurple.TabIndex = 3;
+ panelPurple.MouseDown += panelObject_MouseDown;
+ //
+ // panelBlack
+ //
+ panelBlack.BackColor = Color.Black;
+ panelBlack.Location = new Point(129, 81);
+ panelBlack.Name = "panelBlack";
+ panelBlack.Size = new Size(40, 40);
+ panelBlack.TabIndex = 3;
+ panelBlack.MouseDown += panelObject_MouseDown;
+ //
+ // panelGray
+ //
+ panelGray.BackColor = Color.Gray;
+ panelGray.Location = new Point(73, 81);
+ panelGray.Name = "panelGray";
+ panelGray.Size = new Size(40, 40);
+ panelGray.TabIndex = 3;
+ panelGray.MouseDown += panelObject_MouseDown;
+ //
+ // panelWhite
+ //
+ panelWhite.BackColor = Color.White;
+ panelWhite.Location = new Point(15, 81);
+ panelWhite.Name = "panelWhite";
+ panelWhite.Size = new Size(40, 40);
+ panelWhite.TabIndex = 4;
+ panelWhite.MouseDown += panelObject_MouseDown;
+ //
+ // panelYellow
+ //
+ panelYellow.BackColor = Color.Yellow;
+ panelYellow.Location = new Point(184, 26);
+ panelYellow.Name = "panelYellow";
+ panelYellow.Size = new Size(40, 40);
+ panelYellow.TabIndex = 3;
+ panelYellow.MouseDown += panelObject_MouseDown;
+ //
+ // panelBlue
+ //
+ panelBlue.BackColor = Color.Blue;
+ panelBlue.Location = new Point(129, 26);
+ panelBlue.Name = "panelBlue";
+ panelBlue.Size = new Size(40, 40);
+ panelBlue.TabIndex = 2;
+ panelBlue.MouseDown += panelObject_MouseDown;
+ //
+ // panelGreen
+ //
+ panelGreen.BackColor = Color.Green;
+ panelGreen.Location = new Point(73, 26);
+ panelGreen.Name = "panelGreen";
+ panelGreen.Size = new Size(40, 40);
+ panelGreen.TabIndex = 1;
+ panelGreen.MouseDown += panelObject_MouseDown;
+ //
+ // panelRed
+ //
+ panelRed.BackColor = Color.Red;
+ panelRed.Location = new Point(15, 26);
+ panelRed.Name = "panelRed";
+ panelRed.Size = new Size(40, 40);
+ panelRed.TabIndex = 0;
+ panelRed.MouseDown += panelObject_MouseDown;
+ //
+ // checkBoxBattery
+ //
+ checkBoxBattery.AutoSize = true;
+ checkBoxBattery.Location = new Point(27, 230);
+ checkBoxBattery.Name = "checkBoxBattery";
+ checkBoxBattery.Size = new Size(215, 24);
+ checkBoxBattery.TabIndex = 5;
+ checkBoxBattery.Text = "Признак наличия батареи";
+ checkBoxBattery.UseVisualStyleBackColor = true;
+ //
+ // checkBoxHorns
+ //
+ checkBoxHorns.AutoSize = true;
+ checkBoxHorns.Location = new Point(27, 186);
+ checkBoxHorns.Name = "checkBoxHorns";
+ checkBoxHorns.Size = new Size(199, 24);
+ checkBoxHorns.TabIndex = 4;
+ checkBoxHorns.Text = "Признак наличия рогов";
+ checkBoxHorns.UseVisualStyleBackColor = true;
+ //
+ // numericUpDownWeight
+ //
+ numericUpDownWeight.Location = new Point(109, 105);
+ numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
+ numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
+ numericUpDownWeight.Name = "numericUpDownWeight";
+ numericUpDownWeight.Size = new Size(86, 27);
+ numericUpDownWeight.TabIndex = 3;
+ numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
+ //
+ // numericUpDownSpeed
+ //
+ numericUpDownSpeed.Location = new Point(109, 57);
+ numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
+ numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
+ numericUpDownSpeed.Name = "numericUpDownSpeed";
+ numericUpDownSpeed.Size = new Size(86, 27);
+ numericUpDownSpeed.TabIndex = 2;
+ numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
+ //
+ // label2
+ //
+ label2.AutoSize = true;
+ label2.Location = new Point(27, 107);
+ label2.Name = "label2";
+ label2.Size = new Size(36, 20);
+ label2.TabIndex = 1;
+ label2.Text = "Вес:";
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(27, 59);
+ label1.Name = "label1";
+ label1.Size = new Size(76, 20);
+ label1.TabIndex = 0;
+ label1.Text = "Скорость:";
+ //
+ // pictureBoxObject
+ //
+ pictureBoxObject.Location = new Point(11, 60);
+ pictureBoxObject.Name = "pictureBoxObject";
+ pictureBoxObject.Size = new Size(244, 194);
+ pictureBoxObject.TabIndex = 1;
+ pictureBoxObject.TabStop = false;
+ //
+ // labelBodyColor
+ //
+ labelBodyColor.AllowDrop = true;
+ labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
+ labelBodyColor.Location = new Point(11, 14);
+ labelBodyColor.Name = "labelBodyColor";
+ labelBodyColor.Size = new Size(113, 35);
+ labelBodyColor.TabIndex = 8;
+ labelBodyColor.Text = "Цвет";
+ labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
+ labelBodyColor.DragDrop += labelBodyColor_DragDrop;
+ labelBodyColor.DragEnter += labelObject_DragEnter;
+ //
+ // labelAdditionalColor
+ //
+ labelAdditionalColor.AllowDrop = true;
+ labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
+ labelAdditionalColor.Location = new Point(142, 14);
+ labelAdditionalColor.Name = "labelAdditionalColor";
+ labelAdditionalColor.Size = new Size(113, 35);
+ labelAdditionalColor.TabIndex = 9;
+ labelAdditionalColor.Text = "Доп. цвет";
+ labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
+ labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop;
+ labelAdditionalColor.DragEnter += labelObject_DragEnter;
+ //
+ // buttonOK
+ //
+ buttonOK.Location = new Point(608, 295);
+ buttonOK.Name = "buttonOK";
+ buttonOK.Size = new Size(113, 29);
+ buttonOK.TabIndex = 10;
+ buttonOK.Text = "Добавить";
+ buttonOK.UseVisualStyleBackColor = true;
+ buttonOK.Click += buttonOk_Click;
+ //
+ // buttonClose
+ //
+ buttonClose.Location = new Point(739, 295);
+ buttonClose.Name = "buttonClose";
+ buttonClose.Size = new Size(113, 29);
+ buttonClose.TabIndex = 11;
+ buttonClose.Text = "Отмена";
+ buttonClose.UseVisualStyleBackColor = true;
+ //
+ // panelObject
+ //
+ panelObject.AllowDrop = true;
+ panelObject.Controls.Add(labelAdditionalColor);
+ panelObject.Controls.Add(pictureBoxObject);
+ panelObject.Controls.Add(labelBodyColor);
+ panelObject.Location = new Point(597, 31);
+ panelObject.Name = "panelObject";
+ panelObject.Size = new Size(266, 254);
+ panelObject.TabIndex = 12;
+ panelObject.DragDrop += panelObject_DragDrop;
+ panelObject.DragEnter += panelObject_DragEnter;
+ //
+ // FormLocomotiveConfig
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(911, 339);
+ Controls.Add(buttonClose);
+ Controls.Add(buttonOK);
+ Controls.Add(groupBox1);
+ Controls.Add(panelObject);
+ Name = "FormLocomotiveConfig";
+ Text = "FormLocomotiveConfig";
+ groupBox1.ResumeLayout(false);
+ groupBox1.PerformLayout();
+ groupBox2.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
+ panelObject.ResumeLayout(false);
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBox1;
+ private Label label1;
+ private NumericUpDown numericUpDownWeight;
+ private NumericUpDown numericUpDownSpeed;
+ private Label label2;
+ private CheckBox checkBoxBattery;
+ private CheckBox checkBoxHorns;
+ private GroupBox groupBox2;
+ private Panel panelRed;
+ private Panel panelPurple;
+ private Panel panelBlack;
+ private Panel panelGray;
+ private Panel panelWhite;
+ private Panel panelYellow;
+ private Panel panelBlue;
+ private Panel panelGreen;
+ private Label labelModifiedObject;
+ private Label labelSimpleObject;
+ private PictureBox pictureBoxObject;
+ private Label labelBodyColor;
+ private Label labelAdditionalColor;
+ private Button buttonOK;
+ private Button buttonClose;
+ private Panel panelObject;
+ }
+}
\ No newline at end of file
diff --git a/ElectricLocomotive/FormLocomotiveConfig.cs b/ElectricLocomotive/FormLocomotiveConfig.cs
new file mode 100644
index 0000000..03afa28
--- /dev/null
+++ b/ElectricLocomotive/FormLocomotiveConfig.cs
@@ -0,0 +1,54 @@
+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;
+
+namespace ProjectElectricLocomotive
+{
+ public partial class FormLocomotiveConfig
+ {
+ private void labelObject_MouseDown(object sender, MouseEventArgs e)
+ {
+ (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
+ }
+
+ private void panelObject_MouseDown(object sender, MouseEventArgs e)
+ {
+ (sender as Panel)?.DoDragDrop((sender as Panel)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
+ }
+
+ private void panelObject_DragEnter(object sender, DragEventArgs e)
+ {
+ PanelObject_DragEnter(sender, e);
+ }
+ private void labelObject_DragEnter(object sender, DragEventArgs e)
+ {
+ LabelObject_DragEnter(sender, e);
+ }
+
+ private void labelBodyColor_DragDrop(object sender, DragEventArgs e)
+ {
+ LabelBodyColor_DragDrop(sender, e);
+ }
+
+ private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
+ {
+ LabelAdditionalColor_DragDrop(sender, e);
+ }
+
+ private void panelObject_DragDrop(object sender, DragEventArgs e)
+ {
+ PanelObject_DragDrop(sender, e);
+ }
+
+ private void buttonOk_Click(object sender, EventArgs e)
+ {
+ ButtonOk_Click(sender, e);
+ }
+ }
+}
diff --git a/ElectricLocomotive/FormLocomotiveConfig.resx b/ElectricLocomotive/FormLocomotiveConfig.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ElectricLocomotive/FormLocomotiveConfig.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ElectricLocomotive/LogicFormLocomotiveCollection.cs b/ElectricLocomotive/LogicFormLocomotiveCollection.cs
index faa123f..524dabb 100644
--- a/ElectricLocomotive/LogicFormLocomotiveCollection.cs
+++ b/ElectricLocomotive/LogicFormLocomotiveCollection.cs
@@ -97,17 +97,6 @@ namespace ProjectElectricLocomotive
ReloadObjects();
}
}
- ///
- /// Добавление набора в коллекцию
- ///
- ///
- ///
-
- ///
- /// Выбор набора
- ///
- ///
- ///
///
/// Добавление объекта в набор
@@ -115,6 +104,12 @@ namespace ProjectElectricLocomotive
///
///
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
+ {
+ var formLocomotiveConfig = new FormLocomotiveConfig();
+ formLocomotiveConfig.AddEvent(addLocomotive);
+ formLocomotiveConfig.Show();
+ }
+ private void addLocomotive(DrawningLocomotive SelectedLocomotive)
{
if (listBoxStorages.SelectedIndex == -1)
{
@@ -125,21 +120,19 @@ namespace ProjectElectricLocomotive
{
return;
}
-
- FormLocomotive form = new();
- if (form.ShowDialog() == DialogResult.OK)
+ SelectedLocomotive.SetPictureSize(pictureBoxCollection.Size);
+ if (obj + SelectedLocomotive > 0)
{
- if (obj + form.SelectedLocomotive > 0)
- {
- MessageBox.Show("Объект добавлен");
- pictureBoxCollection.Image = obj.ShowLocomotives();
- }
- else
- {
- MessageBox.Show("Не удалось добавить объект");
- }
+ MessageBox.Show("Объект добавлен");
+
+ pictureBoxCollection.Image = obj.ShowLocomotives();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
}
}
+
///
/// Удаление объекта из набора
///
@@ -162,7 +155,14 @@ namespace ProjectElectricLocomotive
{
return;
}
- int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ int pos;
+ try
+ {
+ pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ } catch(System.FormatException ex)
+ {
+ pos = 0;
+ }
if (obj - pos != -1)
{
MessageBox.Show("Объект удален");
diff --git a/ElectricLocomotive/LogicFormLocomotiveConfig.cs b/ElectricLocomotive/LogicFormLocomotiveConfig.cs
new file mode 100644
index 0000000..a62e59e
--- /dev/null
+++ b/ElectricLocomotive/LogicFormLocomotiveConfig.cs
@@ -0,0 +1,201 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ProjectElectricLocomotive.DrawningObjects;
+using ProjectElectricLocomotive.Entities;
+
+namespace ProjectElectricLocomotive
+{
+ partial class FormLocomotiveConfig : Form
+ {
+ ///
+ /// Переменная-выбранный локомотив
+ ///
+ DrawningLocomotive? _locomotive = null;
+
+ ///
+ /// Событие
+ ///
+ private event Action? EventAddLocomotive;
+
+ ///
+ /// Конструктор
+ ///
+ public FormLocomotiveConfig()
+ {
+ InitializeComponent();
+ panelBlack.MouseDown += PanelColor_MouseDown;
+ panelPurple.MouseDown += PanelColor_MouseDown;
+ panelGray.MouseDown += PanelColor_MouseDown;
+ panelGreen.MouseDown += PanelColor_MouseDown;
+ panelRed.MouseDown += PanelColor_MouseDown;
+ panelWhite.MouseDown += PanelColor_MouseDown;
+ panelYellow.MouseDown += PanelColor_MouseDown;
+ panelBlue.MouseDown += PanelColor_MouseDown;
+ buttonClose.Click += (sender, e) => Close();
+ }
+
+ ///
+ /// Отрисовать локомотив
+ ///
+ private void DrawLocomotive()
+ {
+ Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _locomotive?.SetPosition(5, 5);
+ _locomotive?.DrawTransport(gr);
+ pictureBoxObject.Image = bmp;
+ }
+
+ ///
+ /// Добавление события
+ ///
+ /// Привязанный метод
+ public void AddEvent(Action? ev)
+ {
+ if (EventAddLocomotive == null)
+ {
+ EventAddLocomotive = ev;
+ }
+ else
+ {
+ EventAddLocomotive += ev;
+ }
+ }
+
+ ///
+ /// Передаем информацию при нажатии на Label
+ ///
+ ///
+ ///
+ private void LabelObject_MouseDown(object sender, MouseEventArgs e)
+ {
+ (sender as Label)?.DoDragDrop((sender as Label)?.Name,
+ DragDropEffects.Move | DragDropEffects.Copy);
+ }
+
+ ///
+ /// Проверка получаемой информации (ее типа на соответствие требуемому)
+ ///
+ ///
+ ///
+ private void PanelObject_DragEnter(object sender, DragEventArgs e)
+ {
+ if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
+ }
+
+ ///
+ /// Действия при приеме перетаскиваемой информации
+ ///
+ ///
+ ///
+ private void PanelObject_DragDrop(object sender, DragEventArgs e)
+ {
+ switch (e.Data?.GetData(DataFormats.Text).ToString())
+ {
+ case "labelSimpleObject":
+ _locomotive = new DrawningLocomotive((int)numericUpDownSpeed.Value,
+ (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
+ pictureBoxObject.Height);
+ break;
+ case "labelModifiedObject":
+ _locomotive = new DrawningElectricLocomotive((int)numericUpDownSpeed.Value,
+ (int)numericUpDownWeight.Value, Color.White, Color.Black,
+ checkBoxHorns.Checked, checkBoxBattery.Checked,
+ pictureBoxObject.Width, pictureBoxObject.Height);
+ break;
+ }
+ DrawLocomotive();
+ }
+
+ private void LabelObject_DragEnter(object sender, DragEventArgs e)
+ {
+ if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
+ }
+
+
+ ///
+ /// Передаем информацию при нажатии на Panel
+ ///
+ ///
+ ///
+ private void PanelColor_MouseDown(object sender, MouseEventArgs e)
+ {
+ (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
+ }
+
+ ///
+ /// Передача базового цвета
+ ///
+ ///
+ ///
+ private void LabelBodyColor_DragDrop(object sender, DragEventArgs e)
+ {
+ if (_locomotive is null)
+ {
+ MessageBox.Show("Локомотив не задан");
+ return;
+ }
+ Color bodyColor = (Color)e.Data?.GetData(typeof(Color));
+
+ _locomotive?.EntityLocomotive.ChangeBodyColor(bodyColor);
+ DrawLocomotive();
+ }
+
+ ///
+ /// Передача дополнительного цвета цвета
+ ///
+ ///
+ ///
+ private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
+ {
+ if (_locomotive is null)
+ {
+ MessageBox.Show("Локомотив не задан");
+ return;
+ }
+ Color addColor = (Color)e.Data?.GetData(typeof(Color));
+
+ if (_locomotive is DrawningElectricLocomotive)
+ {
+ (_locomotive?.EntityLocomotive as EntityElectricLocomotive).ChangeAdditionalColor(addColor);
+ }
+ else
+ {
+ MessageBox.Show("Нельзя задать доп. цвет обычному локомотиву");
+ }
+ DrawLocomotive();
+ }
+
+ ///
+ /// Добавление локомотива
+ ///
+ ///
+ ///
+ private void ButtonOk_Click(object sender, EventArgs e)
+ {
+ if (_locomotive is not null)
+ {
+ EventAddLocomotive?.Invoke(_locomotive);
+ }
+ Close();
+ }
+ }
+}
\ No newline at end of file