diff --git a/DumpTruck/DumpTruck/DrawningDumpTruck.cs b/DumpTruck/DumpTruck/DrawningDumpTruck.cs index 1fd16b9..a2a92b3 100644 --- a/DumpTruck/DumpTruck/DrawningDumpTruck.cs +++ b/DumpTruck/DumpTruck/DrawningDumpTruck.cs @@ -20,8 +20,8 @@ namespace DumpTruck.DrawningObjects /// Высота картинки /// true - объект создан, false - проверка не пройдена, public DrawningDumpTruck(int speed, double weight, Color bodyColor, Color - additionalColor, bool trailer, int width, int height) : - base (speed, weight, bodyColor, additionalColor, width, height,110, 85) + additionalColor, bool trailer, int width, int height) + : base (speed, weight, bodyColor, width, height,110, 85) { if (EntityTruck != null) { @@ -40,11 +40,15 @@ namespace DumpTruck.DrawningObjects if (dumpTruck.Trailer) { //прицеп - Brush trailer = new SolidBrush(EntityTruck.AdditionalColor); + Brush trailer = new SolidBrush(dumpTruck.AdditionalColor); g.FillRectangle(trailer, _startPosX, _startPosY, 5, 38); g.FillRectangle(trailer, _startPosX + 5, _startPosY + 33, 70, 5); g.FillRectangle(trailer, _startPosX + 70, _startPosY, 5, 38); } } + public void SetAdditionalColor(Color color) + { + (EntityTruck as EntityDumpTruck).SetAdditionalColor(color); + } } } diff --git a/DumpTruck/DumpTruck/DrawningTruck.cs b/DumpTruck/DumpTruck/DrawningTruck.cs index fff37be..644493a 100644 --- a/DumpTruck/DumpTruck/DrawningTruck.cs +++ b/DumpTruck/DumpTruck/DrawningTruck.cs @@ -71,7 +71,7 @@ namespace DumpTruck.DrawningObjects /// Основной цвет /// Ширина картинки /// Высота картинки - public DrawningTruck(int speed, double weight, Color bodyColor,Color additionalColor, int width, int height) + public DrawningTruck(int speed, double weight, Color bodyColor, int width, int height) { // TODO: Продумать проверки if (width < _truckWidth || height < _truckHeight) @@ -80,7 +80,7 @@ namespace DumpTruck.DrawningObjects } _pictureWidth = width; _pictureHeight = height; - EntityTruck = new EntityTruck(speed, weight, bodyColor, additionalColor); + EntityTruck = new EntityTruck(speed, weight, bodyColor); } /// /// Конструктор @@ -92,7 +92,7 @@ namespace DumpTruck.DrawningObjects /// Высота картинки /// Ширина прорисовки автомобиля /// Высота прорисовки автомобиля - protected DrawningTruck(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height, int truckWidth, int truckHeight) + protected DrawningTruck(int speed, double weight, Color bodyColor, int width, int height, int truckWidth, int truckHeight) { // TODO: Продумать проверки if (width < _truckWidth || height < _truckHeight) @@ -103,7 +103,7 @@ namespace DumpTruck.DrawningObjects _pictureHeight = height; _truckWidth = truckWidth; _truckHeight = truckHeight; - EntityTruck = new EntityTruck(speed, weight, bodyColor, additionalColor); + EntityTruck = new EntityTruck(speed, weight, bodyColor); } /// /// Установка позиции @@ -211,5 +211,10 @@ namespace DumpTruck.DrawningObjects g.FillEllipse(wheels, _startPosX + 25, _startPosY + 63, 25, 25); g.FillEllipse(wheels, _startPosX + 85, _startPosY + 63, 25, 25); } + public void SetBodyColor(Color color) + { + EntityTruck.SetBodyColor(color); + } + } } \ No newline at end of file diff --git a/DumpTruck/DumpTruck/EntityDumpTruck.cs b/DumpTruck/DumpTruck/EntityDumpTruck.cs index 5536a41..b4af1ef 100644 --- a/DumpTruck/DumpTruck/EntityDumpTruck.cs +++ b/DumpTruck/DumpTruck/EntityDumpTruck.cs @@ -12,7 +12,9 @@ namespace DumpTruck.Entities /// Признак (опция) наличия антикрыла /// public bool Trailer { get; private set; } - + public Color AdditionalColor { get; private set; } + + /// Инициализация полей объекта-класса /// /// Скорость @@ -20,9 +22,14 @@ namespace DumpTruck.Entities /// Основной цвет /// Дополнительный цвет public EntityDumpTruck(int speed, double weight, Color bodyColor, Color - additionalColor, bool trailer) : base (speed,weight, bodyColor,additionalColor) + additionalColor, bool trailer) : base (speed,weight, bodyColor) { Trailer = trailer; + AdditionalColor = additionalColor; + } + public void SetAdditionalColor(Color color) + { + AdditionalColor = color; } } } diff --git a/DumpTruck/DumpTruck/EntityTruck.cs b/DumpTruck/DumpTruck/EntityTruck.cs index bef2ece..5c36185 100644 --- a/DumpTruck/DumpTruck/EntityTruck.cs +++ b/DumpTruck/DumpTruck/EntityTruck.cs @@ -23,9 +23,6 @@ namespace DumpTruck.Entities /// Основной цвет /// public Color BodyColor { get; private set; } - - - public Color AdditionalColor { get; private set; } /// /// Шаг перемещения автомобиля /// @@ -36,13 +33,17 @@ namespace DumpTruck.Entities /// Скорость /// Вес автомобиля /// Основной цвет - public EntityTruck(int speed, double weight, Color bodyColor,Color additionalColor) + public EntityTruck(int speed, double weight, Color bodyColor) { Speed = speed; Weight = weight; BodyColor = bodyColor; - AdditionalColor = additionalColor; } + public void SetBodyColor(Color color) + { + BodyColor = color; + } + } } diff --git a/DumpTruck/DumpTruck/FormDumpTruck.cs b/DumpTruck/DumpTruck/FormDumpTruck.cs index bf9d4f7..2c1698e 100644 --- a/DumpTruck/DumpTruck/FormDumpTruck.cs +++ b/DumpTruck/DumpTruck/FormDumpTruck.cs @@ -57,7 +57,7 @@ namespace DumpTruck } _drawningTruck = new DrawningTruck(random.Next(100, 300), random.Next(1000, 3000), - color, color, + color, pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height); _drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); diff --git a/DumpTruck/DumpTruck/FormTruckCollection.cs b/DumpTruck/DumpTruck/FormTruckCollection.cs index f11552f..227e43a 100644 --- a/DumpTruck/DumpTruck/FormTruckCollection.cs +++ b/DumpTruck/DumpTruck/FormTruckCollection.cs @@ -47,32 +47,7 @@ namespace DumpTruck listBoxStorages.SelectedIndex = index; } } - private void buttonAddTruck_Click(object sender, EventArgs e) - { - if (listBoxStorages.SelectedIndex == -1) - { - return; - } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; - if (obj == null) - { - return; - } - FormDumpTruck form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - if (obj + form.selectedTruck != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowTrucks(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } - } + private void buttonRemoveTruck_Click(object sender, EventArgs e) { @@ -133,7 +108,39 @@ namespace DumpTruck _storage.AddSet(textBoxStorageName.Text); ReloadObjects(); } - + private void AddTruck(DrawningTruck truck) + { + truck._pictureWidth = pictureBoxCollection.Width; + truck._pictureHeight = pictureBoxCollection.Height; + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } + if (obj + truck != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowTrucks(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + private void buttonAddTruck_Click(object sender, EventArgs e) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var formTruckConfig = new FormTruckConfig(); + formTruckConfig.AddEvent(AddTruck); + formTruckConfig.Show(); + } private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) { pictureBoxCollection.Image = diff --git a/DumpTruck/DumpTruck/FormTruckConfig.Designer.cs b/DumpTruck/DumpTruck/FormTruckConfig.Designer.cs new file mode 100644 index 0000000..8bfd707 --- /dev/null +++ b/DumpTruck/DumpTruck/FormTruckConfig.Designer.cs @@ -0,0 +1,352 @@ +namespace DumpTruck +{ + partial class FormTruckConfig + { + /// + /// 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() + { + groupBoxConfig = new GroupBox(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + groupBoxColor = new GroupBox(); + panelBlue = new Panel(); + panelLime = new Panel(); + panelRed = new Panel(); + panelOrange = new Panel(); + panelBrown = new Panel(); + panelYellow = new Panel(); + panelBlack = new Panel(); + panelWrite = new Panel(); + checkBoxTrailer = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + label2 = new Label(); + label1 = new Label(); + pictureBoxObject = new PictureBox(); + panelObject = new Panel(); + labelAdditionalColor = new Label(); + labelBodyColor = new Label(); + buttonOk = new Button(); + buttonCancel = new Button(); + groupBoxConfig.SuspendLayout(); + groupBoxColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + panelObject.SuspendLayout(); + SuspendLayout(); + // + // groupBoxConfig + // + groupBoxConfig.Controls.Add(labelModifiedObject); + groupBoxConfig.Controls.Add(labelSimpleObject); + groupBoxConfig.Controls.Add(groupBoxColor); + groupBoxConfig.Controls.Add(checkBoxTrailer); + groupBoxConfig.Controls.Add(numericUpDownWeight); + groupBoxConfig.Controls.Add(numericUpDownSpeed); + groupBoxConfig.Controls.Add(label2); + groupBoxConfig.Controls.Add(label1); + groupBoxConfig.Location = new Point(12, 24); + groupBoxConfig.Name = "groupBoxConfig"; + groupBoxConfig.Size = new Size(724, 393); + groupBoxConfig.TabIndex = 0; + groupBoxConfig.TabStop = false; + groupBoxConfig.Text = "groupBox1"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(550, 264); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(140, 40); + labelModifiedObject.TabIndex = 7; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(317, 264); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(140, 40); + labelSimpleObject.TabIndex = 6; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // groupBoxColor + // + groupBoxColor.Controls.Add(panelBlue); + groupBoxColor.Controls.Add(panelLime); + groupBoxColor.Controls.Add(panelRed); + groupBoxColor.Controls.Add(panelOrange); + groupBoxColor.Controls.Add(panelBrown); + groupBoxColor.Controls.Add(panelYellow); + groupBoxColor.Controls.Add(panelBlack); + groupBoxColor.Controls.Add(panelWrite); + groupBoxColor.Location = new Point(287, 26); + groupBoxColor.Name = "groupBoxColor"; + groupBoxColor.Size = new Size(418, 213); + groupBoxColor.TabIndex = 5; + groupBoxColor.TabStop = false; + groupBoxColor.Text = "groupBox2"; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(317, 123); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(62, 58); + panelBlue.TabIndex = 1; + panelBlue.MouseDown += panelColor_MouseDown; + // + // panelLime + // + panelLime.BackColor = Color.Lime; + panelLime.Location = new Point(225, 123); + panelLime.Name = "panelLime"; + panelLime.Size = new Size(62, 58); + panelLime.TabIndex = 1; + panelLime.MouseDown += panelColor_MouseDown; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(317, 40); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(62, 58); + panelRed.TabIndex = 1; + panelRed.MouseDown += panelColor_MouseDown; + // + // panelOrange + // + panelOrange.BackColor = Color.OrangeRed; + panelOrange.Location = new Point(225, 40); + panelOrange.Name = "panelOrange"; + panelOrange.Size = new Size(62, 58); + panelOrange.TabIndex = 1; + panelOrange.MouseDown += panelColor_MouseDown; + // + // panelBrown + // + panelBrown.BackColor = Color.Brown; + panelBrown.Location = new Point(131, 123); + panelBrown.Name = "panelBrown"; + panelBrown.Size = new Size(62, 58); + panelBrown.TabIndex = 1; + panelBrown.MouseDown += panelColor_MouseDown; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(131, 40); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(62, 58); + panelYellow.TabIndex = 2; + panelYellow.MouseDown += panelColor_MouseDown; + // + // panelBlack + // + panelBlack.BackColor = SystemColors.ActiveCaptionText; + panelBlack.Location = new Point(30, 123); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(62, 58); + panelBlack.TabIndex = 1; + panelBlack.MouseDown += panelColor_MouseDown; + // + // panelWrite + // + panelWrite.BackColor = SystemColors.ButtonHighlight; + panelWrite.Location = new Point(30, 40); + panelWrite.Name = "panelWrite"; + panelWrite.Size = new Size(62, 58); + panelWrite.TabIndex = 0; + panelWrite.MouseDown += panelColor_MouseDown; + // + // checkBoxTrailer + // + checkBoxTrailer.AutoSize = true; + checkBoxTrailer.Location = new Point(48, 160); + checkBoxTrailer.Name = "checkBoxTrailer"; + checkBoxTrailer.Size = new Size(72, 24); + checkBoxTrailer.TabIndex = 4; + checkBoxTrailer.Text = "Trailer"; + checkBoxTrailer.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(133, 111); + 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(77, 27); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(133, 42); + 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(77, 27); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(48, 113); + label2.Name = "label2"; + label2.Size = new Size(36, 20); + label2.TabIndex = 1; + label2.Text = "Вес:"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(48, 49); + label1.Name = "label1"; + label1.Size = new Size(76, 20); + label1.TabIndex = 0; + label1.Text = "Скорость:"; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(12, 38); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(333, 253); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelBodyColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(742, 37); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(363, 326); + panelObject.TabIndex = 3; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(211, 8); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(111, 25); + labelAdditionalColor.TabIndex = 3; + labelAdditionalColor.Text = "Доп Цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.UseMnemonic = false; + labelAdditionalColor.DragDrop += labelColor_DragDrop; + labelAdditionalColor.DragEnter += labelColor_DragEnter; + // + // labelBodyColor + // + labelBodyColor.AllowDrop = true; + labelBodyColor.BorderStyle = BorderStyle.FixedSingle; + labelBodyColor.Location = new Point(42, 8); + labelBodyColor.Name = "labelBodyColor"; + labelBodyColor.Size = new Size(100, 25); + labelBodyColor.TabIndex = 2; + labelBodyColor.Text = "Цвет"; + labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; + labelBodyColor.DragDrop += labelColor_DragDrop; + labelBodyColor.DragEnter += labelColor_DragEnter; + // + // buttonOk + // + buttonOk.Location = new Point(764, 379); + buttonOk.Name = "buttonOk"; + buttonOk.Size = new Size(94, 29); + buttonOk.TabIndex = 4; + buttonOk.Text = "Добавить"; + buttonOk.UseVisualStyleBackColor = true; + buttonOk.Click += buttonOk_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(993, 379); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Удалить"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormTruckConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1132, 455); + Controls.Add(buttonCancel); + Controls.Add(buttonOk); + Controls.Add(panelObject); + Controls.Add(groupBoxConfig); + Name = "FormTruckConfig"; + Text = "Создание объекта"; + groupBoxConfig.ResumeLayout(false); + groupBoxConfig.PerformLayout(); + groupBoxColor.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 groupBoxConfig; + private Label label2; + private Label label1; + private CheckBox checkBoxTrailer; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private GroupBox groupBoxColor; + private Panel panelWrite; + private Panel panelBlue; + private Panel panelLime; + private Panel panelRed; + private Panel panelOrange; + private Panel panelBrown; + private Panel panelYellow; + private Panel panelBlack; + private Label labelModifiedObject; + private Label labelSimpleObject; + private PictureBox pictureBoxObject; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelBodyColor; + private Button buttonOk; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/DumpTruck/DumpTruck/FormTruckConfig.cs b/DumpTruck/DumpTruck/FormTruckConfig.cs new file mode 100644 index 0000000..0fc94c5 --- /dev/null +++ b/DumpTruck/DumpTruck/FormTruckConfig.cs @@ -0,0 +1,175 @@ +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 DumpTruck.DrawningObjects; +using DumpTruck.Generics; +using DumpTruck.MovementStrategy; +using DumpTruck.Entities; + +namespace DumpTruck +{ + public partial class FormTruckConfig : Form + { + /// + /// Переменная-выбранная машина + /// + DrawningTruck? _truck = null; + + /// + /// Событие + /// + private event Action EventAddTruck; + /// + /// Конструктор + /// + public FormTruckConfig() + { + InitializeComponent(); + panelBlack.MouseDown += panelColor_MouseDown; + panelWrite.MouseDown += panelColor_MouseDown; + panelBlue.MouseDown += panelColor_MouseDown; + panelLime.MouseDown += panelColor_MouseDown; + panelRed.MouseDown += panelColor_MouseDown; + panelOrange.MouseDown += panelColor_MouseDown; + panelYellow.MouseDown += panelColor_MouseDown; + panelBrown.MouseDown += panelColor_MouseDown; + + buttonCancel.Click += (sender, e) => Close(); + } + + /// + /// Отрисовать машину + /// + private void DrawTruck() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _truck?.SetPosition(5, 5); + _truck?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + /// + /// Добавление события + /// + /// Привязанный метод + public void AddEvent(Action ev) + { + if (EventAddTruck == null) + { + EventAddTruck = ev; + } + else + { + EventAddTruck += ev; + } + } + + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void panelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, 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 labelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(typeof(Color)) ?? 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": + _truck = new DrawningTruck((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _truck = new DrawningDumpTruck((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, + checkBoxTrailer.Checked, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + } + DrawTruck(); + } + + public void labelColor_DragDrop(object sender, DragEventArgs e) + { + if (_truck == null) + return; + + ((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color)); + switch (((Label)sender).Name) + { + case "labelBodyColor": + _truck.SetBodyColor((Color)e.Data.GetData(typeof(Color))); + break; + case "labelAdditionalColor": + if (!(_truck is DrawningDumpTruck)) + { + return; + } + (_truck as DrawningDumpTruck).SetAdditionalColor((Color)e.Data.GetData(typeof(Color))); + break; + } + DrawTruck(); + } + /// + /// Добавление машины + /// + /// + /// + private void buttonOk_Click(object sender, EventArgs e) + { + EventAddTruck?.Invoke(_truck); + Close(); + } + } +} + diff --git a/DumpTruck/DumpTruck/FormTruckConfig.resx b/DumpTruck/DumpTruck/FormTruckConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/DumpTruck/DumpTruck/FormTruckConfig.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