From 4d68354f6feb3ba038085ff070b8acc623b1a881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=20=D0=94?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=BB=D0=BE=D0=B2?= Date: Sat, 25 Nov 2023 12:51:01 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9E=D1=81=D0=BD=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormTruckConfig.Designer.cs | 347 ++++++++++++++++++ .../Project_DumpTruck/FormTruckConfig.cs | 135 +++++++ .../Project_DumpTruck/FormTruckConfig.resx | 120 ++++++ .../Project_DumpTruck/TruckDelegate.cs | 15 + 4 files changed, 617 insertions(+) create mode 100644 Project_DumpTruck/Project_DumpTruck/FormTruckConfig.Designer.cs create mode 100644 Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs create mode 100644 Project_DumpTruck/Project_DumpTruck/FormTruckConfig.resx create mode 100644 Project_DumpTruck/Project_DumpTruck/TruckDelegate.cs diff --git a/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.Designer.cs b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.Designer.cs new file mode 100644 index 0000000..c41bd72 --- /dev/null +++ b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.Designer.cs @@ -0,0 +1,347 @@ +namespace Project_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() + { + groupBox1 = new GroupBox(); + label4 = new Label(); + label3 = 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(); + checkBoxTent = new CheckBox(); + checkBoxBodyKit = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + label2 = new Label(); + label1 = new Label(); + pictureBoxObject = new PictureBox(); + panel9 = new Panel(); + label6 = new Label(); + label5 = new Label(); + buttonOk = new Button(); + button2 = new Button(); + groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + panel9.SuspendLayout(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(label4); + groupBox1.Controls.Add(label3); + groupBox1.Controls.Add(groupBox2); + groupBox1.Controls.Add(checkBoxTent); + groupBox1.Controls.Add(checkBoxBodyKit); + groupBox1.Controls.Add(numericUpDownWeight); + groupBox1.Controls.Add(numericUpDownSpeed); + groupBox1.Controls.Add(label2); + groupBox1.Controls.Add(label1); + groupBox1.Location = new Point(12, 12); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(444, 196); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Параметры"; + // + // label4 + // + label4.BorderStyle = BorderStyle.FixedSingle; + label4.Location = new Point(344, 156); + label4.Name = "label4"; + label4.Size = new Size(94, 23); + label4.TabIndex = 8; + label4.Text = "Продвинутый"; + label4.TextAlign = ContentAlignment.MiddleCenter; + // + // label3 + // + label3.BorderStyle = BorderStyle.FixedSingle; + label3.Location = new Point(238, 156); + label3.Name = "label3"; + label3.Size = new Size(100, 23); + label3.TabIndex = 7; + label3.Text = "Простой"; + label3.TextAlign = ContentAlignment.MiddleCenter; + label3.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(238, 22); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(200, 127); + groupBox2.TabIndex = 6; + groupBox2.TabStop = false; + groupBox2.Text = "Цвета"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(137, 70); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(33, 32); + panelPurple.TabIndex = 1; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(98, 70); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(33, 32); + panelBlack.TabIndex = 1; + // + // panelGray + // + panelGray.BackColor = Color.Silver; + panelGray.Location = new Point(59, 70); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(33, 32); + panelGray.TabIndex = 1; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(20, 70); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(33, 32); + panelWhite.TabIndex = 1; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(137, 32); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(33, 32); + panelYellow.TabIndex = 1; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(98, 32); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(33, 32); + panelBlue.TabIndex = 1; + // + // panelGreen + // + panelGreen.BackColor = Color.Lime; + panelGreen.Location = new Point(59, 32); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(33, 32); + panelGreen.TabIndex = 1; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(20, 32); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(33, 32); + panelRed.TabIndex = 0; + // + // checkBoxTent + // + checkBoxTent.AutoSize = true; + checkBoxTent.Location = new Point(15, 156); + checkBoxTent.Name = "checkBoxTent"; + checkBoxTent.Size = new Size(155, 19); + checkBoxTent.TabIndex = 5; + checkBoxTent.Text = "Признак наличия тента"; + checkBoxTent.UseVisualStyleBackColor = true; + // + // checkBoxBodyKit + // + checkBoxBodyKit.AutoSize = true; + checkBoxBodyKit.Location = new Point(15, 117); + checkBoxBodyKit.Name = "checkBoxBodyKit"; + checkBoxBodyKit.Size = new Size(162, 19); + checkBoxBodyKit.TabIndex = 4; + checkBoxBodyKit.Text = "Признак наличия кузова"; + checkBoxBodyKit.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(83, 77); + 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(120, 23); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(83, 31); + 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(120, 23); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(15, 79); + label2.Name = "label2"; + label2.Size = new Size(29, 15); + label2.TabIndex = 1; + label2.Text = "Вес:"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(15, 33); + label1.Name = "label1"; + label1.Size = new Size(62, 15); + label1.TabIndex = 0; + label1.Text = "Скорость:"; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(13, 54); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(188, 95); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // panel9 + // + panel9.AllowDrop = true; + panel9.Controls.Add(label6); + panel9.Controls.Add(label5); + panel9.Controls.Add(pictureBoxObject); + panel9.Location = new Point(462, 12); + panel9.Name = "panel9"; + panel9.Size = new Size(221, 160); + panel9.TabIndex = 2; + // + // label6 + // + label6.BorderStyle = BorderStyle.FixedSingle; + label6.Location = new Point(107, 9); + label6.Name = "label6"; + label6.Size = new Size(94, 38); + label6.TabIndex = 9; + label6.Text = "Доп. цвет"; + label6.TextAlign = ContentAlignment.MiddleCenter; + // + // label5 + // + label5.BorderStyle = BorderStyle.FixedSingle; + label5.Location = new Point(13, 9); + label5.Name = "label5"; + label5.Size = new Size(88, 38); + label5.TabIndex = 8; + label5.Text = "Цвет"; + label5.TextAlign = ContentAlignment.MiddleCenter; + // + // buttonOk + // + buttonOk.Location = new Point(475, 185); + buttonOk.Name = "buttonOk"; + buttonOk.Size = new Size(75, 23); + buttonOk.TabIndex = 3; + buttonOk.Text = "Добавить"; + buttonOk.UseVisualStyleBackColor = true; + buttonOk.Click += buttonOk_Click; + // + // button2 + // + button2.Location = new Point(588, 185); + button2.Name = "button2"; + button2.Size = new Size(75, 23); + button2.TabIndex = 4; + button2.Text = "Отмена"; + button2.UseVisualStyleBackColor = true; + // + // FormTruckConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(700, 225); + Controls.Add(button2); + Controls.Add(buttonOk); + Controls.Add(panel9); + Controls.Add(groupBox1); + Name = "FormTruckConfig"; + Text = "Создание объекта"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + panel9.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox1; + private GroupBox groupBox2; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private CheckBox checkBoxTent; + private CheckBox checkBoxBodyKit; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label label2; + private Label label1; + private Label label4; + private Label label3; + private PictureBox pictureBoxObject; + private Panel panel9; + private Label label6; + private Label label5; + private Button buttonOk; + private Button button2; + } +} \ No newline at end of file diff --git a/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs new file mode 100644 index 0000000..1fc3d88 --- /dev/null +++ b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs @@ -0,0 +1,135 @@ +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 Project_DumpTruck.DrawningObjects; + +namespace Project_DumpTruck +{ + public partial class FormTruckConfig : Form + { + /// + /// Переменная-выбранная машина + /// + DrawningTruck? _truck = null; + + /// + /// Событие + /// + private event TruckDelegate? EventAddTruck; + /// + /// Конструктор + /// + public FormTruckConfig() + { + 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; + + // TODO buttonCancel.Click with lambda + } + + /// + /// Отрисовать машину + /// + private void DrawCar() + { + 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(TruckDelegate 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 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": + _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, checkBoxBodyKit.Checked, + checkBoxTent.Checked, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + } + DrawCar(); + } + // TODO Реализовать логику смены цветов: основного и дополнительного(для продвинутого объекта) + + /// + /// Добавление машины + /// + /// + /// + private void buttonOk_Click(object sender, EventArgs e) + { + EventAddTruck?.Invoke(_truck); + Close(); + } + } +} diff --git a/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.resx b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Project_DumpTruck/Project_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 diff --git a/Project_DumpTruck/Project_DumpTruck/TruckDelegate.cs b/Project_DumpTruck/Project_DumpTruck/TruckDelegate.cs new file mode 100644 index 0000000..6761faa --- /dev/null +++ b/Project_DumpTruck/Project_DumpTruck/TruckDelegate.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Project_DumpTruck.DrawningObjects; + +namespace Project_DumpTruck +{ + /// + /// Делегат для передачи объекта-автомобиля + /// + /// + public delegate void TruckDelegate(DrawningTruck Truck); +} -- 2.25.1 From 841f064d03c3e65ef55b59fabed6f0b4861a2f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=20=D0=94?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=BB=D0=BE=D0=B2?= Date: Sat, 25 Nov 2023 16:47:25 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=205=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Project_DumpTruck/DrawningDumpTruck.cs | 5 + .../Project_DumpTruck/DrawningTruck.cs | 9 +- .../Project_DumpTruck/EntityDumpTruck.cs | 5 + .../Project_DumpTruck/EntityTruck.cs | 5 + .../Project_DumpTruck/FormTruckCollection.cs | 38 ++-- .../FormTruckConfig.Designer.cs | 171 ++++++++++-------- .../Project_DumpTruck/FormTruckConfig.cs | 65 +++++-- 7 files changed, 190 insertions(+), 108 deletions(-) diff --git a/Project_DumpTruck/Project_DumpTruck/DrawningDumpTruck.cs b/Project_DumpTruck/Project_DumpTruck/DrawningDumpTruck.cs index 5c38d7b..304626d 100644 --- a/Project_DumpTruck/Project_DumpTruck/DrawningDumpTruck.cs +++ b/Project_DumpTruck/Project_DumpTruck/DrawningDumpTruck.cs @@ -60,5 +60,10 @@ namespace Project_DumpTruck.DrawningObjects } } } + + public void SetAdditionalColor(Color color) + { + (EntityTruck as EntityDumpTruck).SetAdditionalColor(color); + } } } diff --git a/Project_DumpTruck/Project_DumpTruck/DrawningTruck.cs b/Project_DumpTruck/Project_DumpTruck/DrawningTruck.cs index 75a9eeb..5604c1f 100644 --- a/Project_DumpTruck/Project_DumpTruck/DrawningTruck.cs +++ b/Project_DumpTruck/Project_DumpTruck/DrawningTruck.cs @@ -21,11 +21,11 @@ namespace Project_DumpTruck.DrawningObjects /// /// Ширина окна /// - private int _pictureWidth; + public int _pictureWidth; /// /// Высота окна /// - private int _pictureHeight; + public int _pictureHeight; /// /// Левая координата прорисовки автомобиля /// @@ -224,5 +224,10 @@ namespace Project_DumpTruck.DrawningObjects g.DrawEllipse(penBlack, _startPosX + 22, _startPosY + 35, 20, 20); g.DrawEllipse(penBlack, _startPosX + 80, _startPosY + 35, 20, 20); } + + public void SetBodyColor(Color color) + { + EntityTruck.SetBodyColor(color); + } } } diff --git a/Project_DumpTruck/Project_DumpTruck/EntityDumpTruck.cs b/Project_DumpTruck/Project_DumpTruck/EntityDumpTruck.cs index 0c223e8..4b482a4 100644 --- a/Project_DumpTruck/Project_DumpTruck/EntityDumpTruck.cs +++ b/Project_DumpTruck/Project_DumpTruck/EntityDumpTruck.cs @@ -39,5 +39,10 @@ namespace Project_DumpTruck.Entities BodyKit = bodyKit; Tent = tent; } + + public void SetAdditionalColor(Color color) + { + AdditionalColor = color; + } } } diff --git a/Project_DumpTruck/Project_DumpTruck/EntityTruck.cs b/Project_DumpTruck/Project_DumpTruck/EntityTruck.cs index 582ca5a..4499d5a 100644 --- a/Project_DumpTruck/Project_DumpTruck/EntityTruck.cs +++ b/Project_DumpTruck/Project_DumpTruck/EntityTruck.cs @@ -40,5 +40,10 @@ namespace Project_DumpTruck.Entities Weight = weight; BodyColor = bodyColor; } + + public void SetBodyColor(Color color) + { + BodyColor = color; + } } } diff --git a/Project_DumpTruck/Project_DumpTruck/FormTruckCollection.cs b/Project_DumpTruck/Project_DumpTruck/FormTruckCollection.cs index fdd8e02..aa95623 100644 --- a/Project_DumpTruck/Project_DumpTruck/FormTruckCollection.cs +++ b/Project_DumpTruck/Project_DumpTruck/FormTruckCollection.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Numerics; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -51,32 +52,39 @@ namespace Project_DumpTruck } } - - private void buttonAddTruck_Click(object sender, EventArgs e) + 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]; + + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) { return; } - FormDumpTruck form = new(); - if (form.ShowDialog() == DialogResult.OK) + + if (obj + truck != -1) { - if (obj + form.selectedTruck != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowTrucks(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowTrucks(); } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + private void buttonAddTruck_Click(object sender, EventArgs e) + { + var formTruckConfig = new FormTruckConfig(); + formTruckConfig.AddEvent(AddTruck); + formTruckConfig.Show(); } private void buttonRemoveTruck_Click(object sender, EventArgs e) diff --git a/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.Designer.cs b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.Designer.cs index c41bd72..fa89313 100644 --- a/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.Designer.cs +++ b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.Designer.cs @@ -29,8 +29,8 @@ private void InitializeComponent() { groupBox1 = new GroupBox(); - label4 = new Label(); - label3 = new Label(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); groupBox2 = new GroupBox(); panelPurple = new Panel(); panelBlack = new Panel(); @@ -46,24 +46,24 @@ numericUpDownSpeed = new NumericUpDown(); label2 = new Label(); label1 = new Label(); + panelObject = new Panel(); pictureBoxObject = new PictureBox(); - panel9 = new Panel(); - label6 = new Label(); - label5 = new Label(); + labelAdditionalColor = new Label(); + labelColor = new Label(); buttonOk = new Button(); - button2 = new Button(); + buttonCancel = new Button(); groupBox1.SuspendLayout(); groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + panelObject.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); - panel9.SuspendLayout(); SuspendLayout(); // // groupBox1 // - groupBox1.Controls.Add(label4); - groupBox1.Controls.Add(label3); + groupBox1.Controls.Add(labelModifiedObject); + groupBox1.Controls.Add(labelSimpleObject); groupBox1.Controls.Add(groupBox2); groupBox1.Controls.Add(checkBoxTent); groupBox1.Controls.Add(checkBoxBodyKit); @@ -78,26 +78,27 @@ groupBox1.TabStop = false; groupBox1.Text = "Параметры"; // - // label4 + // labelModifiedObject // - label4.BorderStyle = BorderStyle.FixedSingle; - label4.Location = new Point(344, 156); - label4.Name = "label4"; - label4.Size = new Size(94, 23); - label4.TabIndex = 8; - label4.Text = "Продвинутый"; - label4.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(344, 156); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(94, 23); + labelModifiedObject.TabIndex = 8; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; // - // label3 + // labelSimpleObject // - label3.BorderStyle = BorderStyle.FixedSingle; - label3.Location = new Point(238, 156); - label3.Name = "label3"; - label3.Size = new Size(100, 23); - label3.TabIndex = 7; - label3.Text = "Простой"; - label3.TextAlign = ContentAlignment.MiddleCenter; - label3.MouseDown += LabelObject_MouseDown; + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(238, 156); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(100, 23); + labelSimpleObject.TabIndex = 7; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; // // groupBox2 // @@ -123,6 +124,7 @@ panelPurple.Name = "panelPurple"; panelPurple.Size = new Size(33, 32); panelPurple.TabIndex = 1; + panelPurple.MouseDown += panelColor_MouseDown; // // panelBlack // @@ -131,14 +133,16 @@ panelBlack.Name = "panelBlack"; panelBlack.Size = new Size(33, 32); panelBlack.TabIndex = 1; + panelBlack.MouseDown += panelColor_MouseDown; // // panelGray // - panelGray.BackColor = Color.Silver; + panelGray.BackColor = Color.Gray; panelGray.Location = new Point(59, 70); panelGray.Name = "panelGray"; panelGray.Size = new Size(33, 32); panelGray.TabIndex = 1; + panelGray.MouseDown += panelColor_MouseDown; // // panelWhite // @@ -147,6 +151,7 @@ panelWhite.Name = "panelWhite"; panelWhite.Size = new Size(33, 32); panelWhite.TabIndex = 1; + panelWhite.MouseDown += panelColor_MouseDown; // // panelYellow // @@ -155,6 +160,7 @@ panelYellow.Name = "panelYellow"; panelYellow.Size = new Size(33, 32); panelYellow.TabIndex = 1; + panelYellow.MouseDown += panelColor_MouseDown; // // panelBlue // @@ -163,14 +169,16 @@ panelBlue.Name = "panelBlue"; panelBlue.Size = new Size(33, 32); panelBlue.TabIndex = 1; + panelBlue.MouseDown += panelColor_MouseDown; // // panelGreen // - panelGreen.BackColor = Color.Lime; + panelGreen.BackColor = Color.Green; panelGreen.Location = new Point(59, 32); panelGreen.Name = "panelGreen"; panelGreen.Size = new Size(33, 32); panelGreen.TabIndex = 1; + panelGreen.MouseDown += panelColor_MouseDown; // // panelRed // @@ -179,6 +187,7 @@ panelRed.Name = "panelRed"; panelRed.Size = new Size(33, 32); panelRed.TabIndex = 0; + panelRed.MouseDown += panelColor_MouseDown; // // checkBoxTent // @@ -238,48 +247,56 @@ label1.TabIndex = 0; label1.Text = "Скорость:"; // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(pictureBoxObject); + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelColor); + panelObject.Location = new Point(462, 12); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(214, 175); + panelObject.TabIndex = 2; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // // pictureBoxObject // - pictureBoxObject.Location = new Point(13, 54); + pictureBoxObject.Location = new Point(13, 50); pictureBoxObject.Name = "pictureBoxObject"; - pictureBoxObject.Size = new Size(188, 95); - pictureBoxObject.TabIndex = 1; + pictureBoxObject.Size = new Size(188, 122); + pictureBoxObject.TabIndex = 10; pictureBoxObject.TabStop = false; // - // panel9 + // labelAdditionalColor // - panel9.AllowDrop = true; - panel9.Controls.Add(label6); - panel9.Controls.Add(label5); - panel9.Controls.Add(pictureBoxObject); - panel9.Location = new Point(462, 12); - panel9.Name = "panel9"; - panel9.Size = new Size(221, 160); - panel9.TabIndex = 2; + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(107, 9); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(94, 38); + labelAdditionalColor.TabIndex = 9; + labelAdditionalColor.Text = "Доп. цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += labelColor_DragDrop; + labelAdditionalColor.DragEnter += labelColor_DragEnter; // - // label6 + // labelColor // - label6.BorderStyle = BorderStyle.FixedSingle; - label6.Location = new Point(107, 9); - label6.Name = "label6"; - label6.Size = new Size(94, 38); - label6.TabIndex = 9; - label6.Text = "Доп. цвет"; - label6.TextAlign = ContentAlignment.MiddleCenter; - // - // label5 - // - label5.BorderStyle = BorderStyle.FixedSingle; - label5.Location = new Point(13, 9); - label5.Name = "label5"; - label5.Size = new Size(88, 38); - label5.TabIndex = 8; - label5.Text = "Цвет"; - label5.TextAlign = ContentAlignment.MiddleCenter; + labelColor.AllowDrop = true; + labelColor.BorderStyle = BorderStyle.FixedSingle; + labelColor.Location = new Point(13, 9); + labelColor.Name = "labelColor"; + labelColor.Size = new Size(88, 38); + labelColor.TabIndex = 8; + labelColor.Text = "Цвет"; + labelColor.TextAlign = ContentAlignment.MiddleCenter; + labelColor.DragDrop += labelColor_DragDrop; + labelColor.DragEnter += labelColor_DragEnter; // // buttonOk // - buttonOk.Location = new Point(475, 185); + buttonOk.Location = new Point(475, 193); buttonOk.Name = "buttonOk"; buttonOk.Size = new Size(75, 23); buttonOk.TabIndex = 3; @@ -287,23 +304,23 @@ buttonOk.UseVisualStyleBackColor = true; buttonOk.Click += buttonOk_Click; // - // button2 + // buttonCancel // - button2.Location = new Point(588, 185); - button2.Name = "button2"; - button2.Size = new Size(75, 23); - button2.TabIndex = 4; - button2.Text = "Отмена"; - button2.UseVisualStyleBackColor = true; + buttonCancel.Location = new Point(588, 193); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; // // FormTruckConfig // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(700, 225); - Controls.Add(button2); + ClientSize = new Size(690, 227); + Controls.Add(buttonCancel); Controls.Add(buttonOk); - Controls.Add(panel9); + Controls.Add(panelObject); Controls.Add(groupBox1); Name = "FormTruckConfig"; Text = "Создание объекта"; @@ -312,8 +329,8 @@ groupBox2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + panelObject.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); - panel9.ResumeLayout(false); ResumeLayout(false); } @@ -335,13 +352,13 @@ private NumericUpDown numericUpDownSpeed; private Label label2; private Label label1; - private Label label4; - private Label label3; - private PictureBox pictureBoxObject; - private Panel panel9; - private Label label6; - private Label label5; + private Label labelModifiedObject; + private Label labelSimpleObject; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelColor; private Button buttonOk; - private Button button2; + private Button buttonCancel; + private PictureBox pictureBoxObject; } } \ No newline at end of file diff --git a/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs index 1fc3d88..9054dc7 100644 --- a/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs +++ b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs @@ -28,22 +28,22 @@ namespace Project_DumpTruck public FormTruckConfig() { 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; + 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; - // TODO buttonCancel.Click with lambda + buttonCancel.Click += (sender, e) => Close(); } /// /// Отрисовать машину /// - private void DrawCar() + private void DrawTruck() { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Graphics gr = Graphics.FromImage(bmp); @@ -75,8 +75,12 @@ namespace Project_DumpTruck /// private void LabelObject_MouseDown(object sender, MouseEventArgs e) { - (sender as Label)?.DoDragDrop((sender as Label)?.Name, - DragDropEffects.Move | DragDropEffects.Copy); + (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); } /// @@ -96,6 +100,18 @@ namespace Project_DumpTruck } } + private void labelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(typeof(Color)) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + /// /// Действия при приеме перетаскиваемой информации /// @@ -117,9 +133,30 @@ namespace Project_DumpTruck pictureBoxObject.Height); break; } - DrawCar(); + DrawTruck(); + } + + private 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 "labelColor": + _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(); } - // TODO Реализовать логику смены цветов: основного и дополнительного(для продвинутого объекта) /// /// Добавление машины -- 2.25.1 From fac6bdd2150bc26a887cae5f8cf7b81938f77206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=20=D0=94?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=BB=D0=BE=D0=B2?= Date: Sat, 2 Dec 2023 23:53:20 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=BD=D1=8F=D1=82=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Project_DumpTruck/FormTruckConfig.cs | 4 ++-- .../Project_DumpTruck/TruckDelegate.cs | 15 --------------- 2 files changed, 2 insertions(+), 17 deletions(-) delete mode 100644 Project_DumpTruck/Project_DumpTruck/TruckDelegate.cs diff --git a/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs index 9054dc7..bc48611 100644 --- a/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs +++ b/Project_DumpTruck/Project_DumpTruck/FormTruckConfig.cs @@ -21,7 +21,7 @@ namespace Project_DumpTruck /// /// Событие /// - private event TruckDelegate? EventAddTruck; + private event Action EventAddTruck; /// /// Конструктор /// @@ -56,7 +56,7 @@ namespace Project_DumpTruck /// Добавление события /// /// Привязанный метод - public void AddEvent(TruckDelegate ev) + public void AddEvent(Action ev) { if (EventAddTruck == null) { diff --git a/Project_DumpTruck/Project_DumpTruck/TruckDelegate.cs b/Project_DumpTruck/Project_DumpTruck/TruckDelegate.cs deleted file mode 100644 index 6761faa..0000000 --- a/Project_DumpTruck/Project_DumpTruck/TruckDelegate.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Project_DumpTruck.DrawningObjects; - -namespace Project_DumpTruck -{ - /// - /// Делегат для передачи объекта-автомобиля - /// - /// - public delegate void TruckDelegate(DrawningTruck Truck); -} -- 2.25.1