From de631fcdf5ab20388ff66daa64ba09b5858e82f3 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Wed, 8 Nov 2023 23:23:24 +0400 Subject: [PATCH 1/3] Lab4 Done --- Trolleybus/Trolleybus/BusDelegate.cs | 11 + Trolleybus/Trolleybus/FormBusCollection.cs | 13 +- .../Trolleybus/FormBusConfig.Designer.cs | 365 ++++++++++++++++++ Trolleybus/Trolleybus/FormBusConfig.cs | 160 ++++++++ Trolleybus/Trolleybus/FormBusConfig.resx | 120 ++++++ .../Trolleybus/FormTrolleybus.Designer.cs | 8 +- .../Properties/Resources.Designer.cs | 2 +- 7 files changed, 669 insertions(+), 10 deletions(-) create mode 100644 Trolleybus/Trolleybus/BusDelegate.cs create mode 100644 Trolleybus/Trolleybus/FormBusConfig.Designer.cs create mode 100644 Trolleybus/Trolleybus/FormBusConfig.cs create mode 100644 Trolleybus/Trolleybus/FormBusConfig.resx diff --git a/Trolleybus/Trolleybus/BusDelegate.cs b/Trolleybus/Trolleybus/BusDelegate.cs new file mode 100644 index 0000000..c0eb1f3 --- /dev/null +++ b/Trolleybus/Trolleybus/BusDelegate.cs @@ -0,0 +1,11 @@ +using ProjectTrolleybus.DrawingObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTrolleybus +{ + public delegate void BusDelegate(DrawingBus bus); +} diff --git a/Trolleybus/Trolleybus/FormBusCollection.cs b/Trolleybus/Trolleybus/FormBusCollection.cs index f79cdde..0586524 100644 --- a/Trolleybus/Trolleybus/FormBusCollection.cs +++ b/Trolleybus/Trolleybus/FormBusCollection.cs @@ -10,6 +10,7 @@ using System.Windows.Forms; using ProjectTrolleybus.DrawingObjects; using ProjectTrolleybus.MovementStrategy; using ProjectTrolleybus.Generics; +using ProjectTrolleybus; namespace ProjectTrolleybus { @@ -80,10 +81,11 @@ namespace ProjectTrolleybus { return; } - FormTrolleybus form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - if (obj + form.SelectedBus) + FormBusConfig form = new FormBusConfig(pictureBoxCollection.Width, pictureBoxCollection.Height); + form.Show(); + BusDelegate? busDelegate = new((m) => { + bool q = (obj + m); + if (q) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowBuses(); @@ -92,7 +94,8 @@ namespace ProjectTrolleybus { MessageBox.Show("Не удалось добавить объект"); } - } + }); + form.AddEvent(busDelegate); } private void ButtonRemoveBus_Click(object sender, EventArgs e) { diff --git a/Trolleybus/Trolleybus/FormBusConfig.Designer.cs b/Trolleybus/Trolleybus/FormBusConfig.Designer.cs new file mode 100644 index 0000000..9dd3f36 --- /dev/null +++ b/Trolleybus/Trolleybus/FormBusConfig.Designer.cs @@ -0,0 +1,365 @@ +namespace ProjectTrolleybus +{ + partial class FormBusConfig + { + /// + /// 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(); + labelAdvanced = new Label(); + labelSimple = new Label(); + groupBoxColor = 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(); + checkBoxRoga = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + labelWeight = new Label(); + labelSpeed = new Label(); + panelAllow = new Panel(); + pictureBoxObject = new PictureBox(); + labelAdditionalColor = new Label(); + labelColor = new Label(); + buttonAdd = new Button(); + buttonCancel = new Button(); + groupBoxConfig.SuspendLayout(); + groupBoxColor.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + panelAllow.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // groupBoxConfig + // + groupBoxConfig.Controls.Add(labelAdvanced); + groupBoxConfig.Controls.Add(labelSimple); + groupBoxConfig.Controls.Add(groupBoxColor); + groupBoxConfig.Controls.Add(checkBoxBattery); + groupBoxConfig.Controls.Add(checkBoxRoga); + groupBoxConfig.Controls.Add(numericUpDownWeight); + groupBoxConfig.Controls.Add(numericUpDownSpeed); + groupBoxConfig.Controls.Add(labelWeight); + groupBoxConfig.Controls.Add(labelSpeed); + groupBoxConfig.Location = new Point(12, 12); + groupBoxConfig.Name = "groupBoxConfig"; + groupBoxConfig.Size = new Size(737, 337); + groupBoxConfig.TabIndex = 0; + groupBoxConfig.TabStop = false; + groupBoxConfig.Text = "Параметры"; + // + // labelAdvanced + // + labelAdvanced.BorderStyle = BorderStyle.FixedSingle; + labelAdvanced.Location = new Point(574, 262); + labelAdvanced.Name = "labelAdvanced"; + labelAdvanced.Size = new Size(120, 52); + labelAdvanced.TabIndex = 8; + labelAdvanced.Text = "Продвинутый"; + labelAdvanced.TextAlign = ContentAlignment.MiddleCenter; + labelAdvanced.MouseDown += LabelObject_MouseDown; + // + // labelSimple + // + labelSimple.BorderStyle = BorderStyle.FixedSingle; + labelSimple.Location = new Point(443, 262); + labelSimple.Name = "labelSimple"; + labelSimple.Size = new Size(116, 52); + labelSimple.TabIndex = 7; + labelSimple.Text = "Простой"; + labelSimple.TextAlign = ContentAlignment.MiddleCenter; + labelSimple.MouseDown += LabelObject_MouseDown; + // + // groupBoxColor + // + groupBoxColor.Controls.Add(panelPurple); + groupBoxColor.Controls.Add(panelBlack); + groupBoxColor.Controls.Add(panelGray); + groupBoxColor.Controls.Add(panelWhite); + groupBoxColor.Controls.Add(panelYellow); + groupBoxColor.Controls.Add(panelBlue); + groupBoxColor.Controls.Add(panelGreen); + groupBoxColor.Controls.Add(panelRed); + groupBoxColor.Location = new Point(411, 53); + groupBoxColor.Name = "groupBoxColor"; + groupBoxColor.Size = new Size(306, 182); + groupBoxColor.TabIndex = 6; + groupBoxColor.TabStop = false; + groupBoxColor.Text = "Цвета"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(236, 98); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(58, 49); + panelPurple.TabIndex = 1; + panelPurple.MouseDown += PanelColor_MouseDown; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(163, 98); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(58, 49); + panelBlack.TabIndex = 1; + panelBlack.MouseDown += PanelColor_MouseDown; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(90, 98); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(58, 49); + panelGray.TabIndex = 1; + panelGray.MouseDown += PanelColor_MouseDown; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(15, 98); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(58, 49); + panelWhite.TabIndex = 1; + panelWhite.MouseDown += PanelColor_MouseDown; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(236, 33); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(58, 49); + panelYellow.TabIndex = 1; + panelYellow.MouseDown += PanelColor_MouseDown; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(163, 33); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(58, 49); + panelBlue.TabIndex = 1; + panelBlue.MouseDown += PanelColor_MouseDown; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(90, 33); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(58, 49); + panelGreen.TabIndex = 1; + panelGreen.MouseDown += PanelColor_MouseDown; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(15, 33); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(58, 49); + panelRed.TabIndex = 0; + panelRed.MouseDown += PanelColor_MouseDown; + // + // checkBoxBattery + // + checkBoxBattery.AutoSize = true; + checkBoxBattery.Location = new Point(6, 214); + checkBoxBattery.Name = "checkBoxBattery"; + checkBoxBattery.Size = new Size(399, 24); + checkBoxBattery.TabIndex = 5; + checkBoxBattery.Text = "Признак наличия отсека под электрические батареи"; + checkBoxBattery.UseVisualStyleBackColor = true; + // + // checkBoxRoga + // + checkBoxRoga.AutoSize = true; + checkBoxRoga.Location = new Point(6, 171); + checkBoxRoga.Name = "checkBoxRoga"; + checkBoxRoga.Size = new Size(277, 24); + checkBoxRoga.TabIndex = 4; + checkBoxRoga.Text = "Признак наличия токоприёмников"; + checkBoxRoga.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(102, 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(150, 27); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(102, 53); + 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(150, 27); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(6, 113); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(36, 20); + labelWeight.TabIndex = 1; + labelWeight.Text = "Вес:"; + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(6, 55); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(76, 20); + labelSpeed.TabIndex = 0; + labelSpeed.Text = "Скорость:"; + // + // panelAllow + // + panelAllow.AllowDrop = true; + panelAllow.Controls.Add(pictureBoxObject); + panelAllow.Controls.Add(labelAdditionalColor); + panelAllow.Controls.Add(labelColor); + panelAllow.Location = new Point(755, 12); + panelAllow.Name = "panelAllow"; + panelAllow.Size = new Size(362, 292); + panelAllow.TabIndex = 1; + panelAllow.DragDrop += PanelObject_DragDrop; + panelAllow.DragEnter += PanelObject_DragEnter; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(61, 86); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(227, 161); + pictureBoxObject.TabIndex = 2; + pictureBoxObject.TabStop = false; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(200, 13); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(129, 49); + labelAdditionalColor.TabIndex = 1; + labelAdditionalColor.Text = "Доп. цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += labelAdditionalColor_DragEnter; + // + // labelColor + // + labelColor.AllowDrop = true; + labelColor.BorderStyle = BorderStyle.FixedSingle; + labelColor.Location = new Point(26, 13); + labelColor.Name = "labelColor"; + labelColor.Size = new Size(142, 49); + labelColor.TabIndex = 0; + labelColor.Text = "Цвет"; + labelColor.TextAlign = ContentAlignment.MiddleCenter; + labelColor.DragDrop += labelColor_DragDrop; + labelColor.DragEnter += labelColor_DragEnter; + // + // buttonAdd + // + buttonAdd.Location = new Point(781, 321); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(142, 45); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonOk_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(955, 321); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(129, 45); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormBusConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1123, 386); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(panelAllow); + Controls.Add(groupBoxConfig); + Name = "FormBusConfig"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Создание объекта"; + groupBoxConfig.ResumeLayout(false); + groupBoxConfig.PerformLayout(); + groupBoxColor.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + panelAllow.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxConfig; + private Label labelSpeed; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelWeight; + private GroupBox groupBoxColor; + private CheckBox checkBoxBattery; + private CheckBox checkBoxRoga; + 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 Label labelAdvanced; + private Label labelSimple; + private Panel panelAllow; + private Label labelColor; + private PictureBox pictureBoxObject; + private Label labelAdditionalColor; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Trolleybus/Trolleybus/FormBusConfig.cs b/Trolleybus/Trolleybus/FormBusConfig.cs new file mode 100644 index 0000000..b5f250e --- /dev/null +++ b/Trolleybus/Trolleybus/FormBusConfig.cs @@ -0,0 +1,160 @@ +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 ProjectTrolleybus.DrawingObjects; +using ProjectTrolleybus.Entities; + +namespace ProjectTrolleybus +{ + public partial class FormBusConfig : Form + { + private readonly int PictureWidth; + private readonly int PictureHeight; + + DrawingBus? _bus = null; + + private event BusDelegate? EventAddBus; + + public FormBusConfig(int Width, int Height) + { + 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; + buttonCancel.Click += (s, e) => Close(); + PictureWidth = Width; + PictureHeight = Height; + } + + private void DrawBus() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _bus?.SetPosition(5, 5); _bus?.DrawTransport(gr); pictureBoxObject.Image = bmp; + } + + public void AddEvent(BusDelegate ev) + { + if (EventAddBus == null) + { + EventAddBus = ev; + } + else + { + EventAddBus += ev; + } + } + + 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 "labelSimple": + _bus = new DrawingBus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, PictureWidth, PictureHeight); break; + case "labelAdvanced": + _bus = new DrawingTrolleybus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxRoga.Checked, checkBoxBattery.Checked, PictureWidth, PictureHeight); break; + } + DrawBus(); + } + + private void PanelColor_MouseDown(object? sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, + DragDropEffects.Move | DragDropEffects.Copy); + + } + + private void ButtonOk_Click(object sender, EventArgs e) + { + if (_bus == null) + return; + EventAddBus?.Invoke(_bus); + Close(); + } + + private void labelAdditionalColor_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 (_bus == null || _bus.EntityBus == null || _bus is DrawingTrolleybus == false) + return; + Color colorAdditional = (Color)e.Data.GetData(typeof(Color)); + _bus = new DrawingTrolleybus(_bus.EntityBus.Speed, _bus.EntityBus.Weight, + _bus.EntityBus.BodyColor, colorAdditional, ((EntityTrolleybus)_bus.EntityBus).Roga, + ((EntityTrolleybus)_bus.EntityBus).Battery, PictureWidth, PictureHeight); + DrawBus(); + } + + private void labelColor_DragDrop(object sender, DragEventArgs e) + { + if (_bus == null || _bus.EntityBus == null) + return; + Color color = (Color)e.Data.GetData(typeof(Color)); + if (_bus is DrawingTrolleybus == false) + { + _bus = new DrawingBus(_bus.EntityBus.Speed, _bus.EntityBus.Weight, + color, PictureWidth, PictureHeight); + } + else + { + _bus = new DrawingTrolleybus(_bus.EntityBus.Speed, _bus.EntityBus.Weight, + color, ((EntityTrolleybus)_bus.EntityBus).AdditionalColor, ((EntityTrolleybus)_bus.EntityBus).Roga, + ((EntityTrolleybus)_bus.EntityBus).Battery, PictureWidth, PictureHeight); + + } + DrawBus(); + } + + private void labelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } +} + diff --git a/Trolleybus/Trolleybus/FormBusConfig.resx b/Trolleybus/Trolleybus/FormBusConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Trolleybus/Trolleybus/FormBusConfig.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/Trolleybus/Trolleybus/FormTrolleybus.Designer.cs b/Trolleybus/Trolleybus/FormTrolleybus.Designer.cs index a8b1e6c..1d9cbb7 100644 --- a/Trolleybus/Trolleybus/FormTrolleybus.Designer.cs +++ b/Trolleybus/Trolleybus/FormTrolleybus.Designer.cs @@ -55,7 +55,7 @@ // buttonRight // buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonRight.BackgroundImage = Trolleybus.Properties.Resources.Right; + buttonRight.BackgroundImage = ProjectTrolleybus.Properties.Resources.Right; buttonRight.BackgroundImageLayout = ImageLayout.Zoom; buttonRight.Location = new Point(842, 419); buttonRight.Name = "buttonRight"; @@ -67,7 +67,7 @@ // buttonDown // buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonDown.BackgroundImage = Trolleybus.Properties.Resources.Down; + buttonDown.BackgroundImage = ProjectTrolleybus.Properties.Resources.Down; buttonDown.BackgroundImageLayout = ImageLayout.Zoom; buttonDown.Location = new Point(806, 419); buttonDown.Name = "buttonDown"; @@ -79,7 +79,7 @@ // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonLeft.BackgroundImage = Trolleybus.Properties.Resources.Left; + buttonLeft.BackgroundImage = ProjectTrolleybus.Properties.Resources.Left; buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; buttonLeft.Location = new Point(770, 419); buttonLeft.Name = "buttonLeft"; @@ -91,7 +91,7 @@ // buttonUp // buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonUp.BackgroundImage = Trolleybus.Properties.Resources.Up; + buttonUp.BackgroundImage = ProjectTrolleybus.Properties.Resources.Up; buttonUp.BackgroundImageLayout = ImageLayout.Zoom; buttonUp.Location = new Point(806, 383); buttonUp.Name = "buttonUp"; diff --git a/Trolleybus/Trolleybus/Properties/Resources.Designer.cs b/Trolleybus/Trolleybus/Properties/Resources.Designer.cs index 6d1b175..4f5cd4d 100644 --- a/Trolleybus/Trolleybus/Properties/Resources.Designer.cs +++ b/Trolleybus/Trolleybus/Properties/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Trolleybus.Properties { +namespace ProjectTrolleybus.Properties { using System; -- 2.25.1 From f31ccdc5933e612fe51c08a9e201d58539868b77 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Fri, 17 Nov 2023 17:53:02 +0400 Subject: [PATCH 2/3] Lab5 Done --- Trolleybus/Trolleybus/BusDelegate.cs | 11 --- Trolleybus/Trolleybus/FormBusCollection.cs | 17 ++--- Trolleybus/Trolleybus/FormBusConfig.cs | 83 ++++++++++++---------- 3 files changed, 51 insertions(+), 60 deletions(-) delete mode 100644 Trolleybus/Trolleybus/BusDelegate.cs diff --git a/Trolleybus/Trolleybus/BusDelegate.cs b/Trolleybus/Trolleybus/BusDelegate.cs deleted file mode 100644 index c0eb1f3..0000000 --- a/Trolleybus/Trolleybus/BusDelegate.cs +++ /dev/null @@ -1,11 +0,0 @@ -using ProjectTrolleybus.DrawingObjects; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectTrolleybus -{ - public delegate void BusDelegate(DrawingBus bus); -} diff --git a/Trolleybus/Trolleybus/FormBusCollection.cs b/Trolleybus/Trolleybus/FormBusCollection.cs index 0586524..5148483 100644 --- a/Trolleybus/Trolleybus/FormBusCollection.cs +++ b/Trolleybus/Trolleybus/FormBusCollection.cs @@ -64,8 +64,7 @@ namespace ProjectTrolleybus } if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - _storage.DelSet(listBoxStorages.SelectedItem.ToString() - ?? string.Empty); + _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty); ReloadObjects(); } } @@ -75,17 +74,15 @@ namespace ProjectTrolleybus { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; } FormBusConfig form = new FormBusConfig(pictureBoxCollection.Width, pictureBoxCollection.Height); form.Show(); - BusDelegate? busDelegate = new((m) => { - bool q = (obj + m); - if (q) + Action? busDelegate = new((bus) => { + if (obj + bus) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowBuses(); @@ -103,8 +100,7 @@ namespace ProjectTrolleybus { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; @@ -131,8 +127,7 @@ namespace ProjectTrolleybus { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; diff --git a/Trolleybus/Trolleybus/FormBusConfig.cs b/Trolleybus/Trolleybus/FormBusConfig.cs index b5f250e..76da4e4 100644 --- a/Trolleybus/Trolleybus/FormBusConfig.cs +++ b/Trolleybus/Trolleybus/FormBusConfig.cs @@ -14,12 +14,12 @@ namespace ProjectTrolleybus { public partial class FormBusConfig : Form { - private readonly int PictureWidth; - private readonly int PictureHeight; + private readonly int _pictureWidth; + private readonly int _pictureHeight; DrawingBus? _bus = null; - private event BusDelegate? EventAddBus; + Action? EventAddBus; public FormBusConfig(int Width, int Height) { @@ -33,18 +33,20 @@ namespace ProjectTrolleybus panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; buttonCancel.Click += (s, e) => Close(); - PictureWidth = Width; - PictureHeight = Height; + _pictureWidth = Width; + _pictureHeight = Height; } private void DrawBus() { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Graphics gr = Graphics.FromImage(bmp); - _bus?.SetPosition(5, 5); _bus?.DrawTransport(gr); pictureBoxObject.Image = bmp; + _bus?.SetPosition(5, 5); + _bus?.DrawTransport(gr); + pictureBoxObject.Image = bmp; } - public void AddEvent(BusDelegate ev) + public void AddEvent(Action ev) { if (EventAddBus == null) { @@ -79,9 +81,14 @@ namespace ProjectTrolleybus switch (e.Data?.GetData(DataFormats.Text).ToString()) { case "labelSimple": - _bus = new DrawingBus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, PictureWidth, PictureHeight); break; + _bus = new DrawingBus((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, _pictureWidth, _pictureHeight); + break; case "labelAdvanced": - _bus = new DrawingTrolleybus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxRoga.Checked, checkBoxBattery.Checked, PictureWidth, PictureHeight); break; + _bus = new DrawingTrolleybus((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxRoga.Checked, + checkBoxBattery.Checked, _pictureWidth, _pictureHeight); + break; } DrawBus(); } @@ -101,44 +108,21 @@ namespace ProjectTrolleybus Close(); } - private void labelAdditionalColor_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 (_bus == null || _bus.EntityBus == null || _bus is DrawingTrolleybus == false) - return; - Color colorAdditional = (Color)e.Data.GetData(typeof(Color)); - _bus = new DrawingTrolleybus(_bus.EntityBus.Speed, _bus.EntityBus.Weight, - _bus.EntityBus.BodyColor, colorAdditional, ((EntityTrolleybus)_bus.EntityBus).Roga, - ((EntityTrolleybus)_bus.EntityBus).Battery, PictureWidth, PictureHeight); - DrawBus(); - } - private void labelColor_DragDrop(object sender, DragEventArgs e) { if (_bus == null || _bus.EntityBus == null) return; - Color color = (Color)e.Data.GetData(typeof(Color)); + Color colorBody = (Color)e.Data.GetData(typeof(Color)); if (_bus is DrawingTrolleybus == false) { - _bus = new DrawingBus(_bus.EntityBus.Speed, _bus.EntityBus.Weight, - color, PictureWidth, PictureHeight); + _bus = new DrawingBus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, + colorBody, _pictureWidth, _pictureHeight); } else { - _bus = new DrawingTrolleybus(_bus.EntityBus.Speed, _bus.EntityBus.Weight, - color, ((EntityTrolleybus)_bus.EntityBus).AdditionalColor, ((EntityTrolleybus)_bus.EntityBus).Roga, - ((EntityTrolleybus)_bus.EntityBus).Battery, PictureWidth, PictureHeight); + _bus = new DrawingTrolleybus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, + colorBody, ((EntityTrolleybus)_bus.EntityBus).AdditionalColor, checkBoxRoga.Checked, + checkBoxBattery.Checked, _pictureWidth, _pictureHeight); } DrawBus(); @@ -155,6 +139,29 @@ namespace ProjectTrolleybus e.Effect = DragDropEffects.None; } } + + private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_bus == null || _bus.EntityBus == null || _bus is DrawingTrolleybus == false) + return; + Color colorAdditional = (Color)e.Data.GetData(typeof(Color)); + _bus = new DrawingTrolleybus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, + _bus.EntityBus.BodyColor, colorAdditional, checkBoxRoga.Checked, + checkBoxBattery.Checked, _pictureWidth, _pictureHeight); + DrawBus(); + } + + private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } } } -- 2.25.1 From 3bd218f6649347faa1c6a3ebe32edddd3c034e04 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Wed, 22 Nov 2023 19:42:40 +0400 Subject: [PATCH 3/3] Lab5 error fix --- Trolleybus/Trolleybus/EntityBus.cs | 4 +++ Trolleybus/Trolleybus/EntityTrolleybus.cs | 5 +++ .../Trolleybus/FormBusConfig.Designer.cs | 2 +- Trolleybus/Trolleybus/FormBusConfig.cs | 35 +++---------------- 4 files changed, 15 insertions(+), 31 deletions(-) diff --git a/Trolleybus/Trolleybus/EntityBus.cs b/Trolleybus/Trolleybus/EntityBus.cs index ecb9c71..a2b6cea 100644 --- a/Trolleybus/Trolleybus/EntityBus.cs +++ b/Trolleybus/Trolleybus/EntityBus.cs @@ -22,5 +22,9 @@ namespace ProjectTrolleybus.Entities Weight = weight; BodyColor = bodyColor; } + public void ChangeColor(Color color) + { + BodyColor = color; + } } } diff --git a/Trolleybus/Trolleybus/EntityTrolleybus.cs b/Trolleybus/Trolleybus/EntityTrolleybus.cs index 805e589..b052df9 100644 --- a/Trolleybus/Trolleybus/EntityTrolleybus.cs +++ b/Trolleybus/Trolleybus/EntityTrolleybus.cs @@ -22,5 +22,10 @@ namespace ProjectTrolleybus.Entities Roga = roga; Battery = battery; } + + public void ChangeAdditColor(Color color) + { + AdditionalColor = color; + } } } diff --git a/Trolleybus/Trolleybus/FormBusConfig.Designer.cs b/Trolleybus/Trolleybus/FormBusConfig.Designer.cs index 9dd3f36..56a3d63 100644 --- a/Trolleybus/Trolleybus/FormBusConfig.Designer.cs +++ b/Trolleybus/Trolleybus/FormBusConfig.Designer.cs @@ -279,7 +279,7 @@ labelAdditionalColor.Text = "Доп. цвет"; labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop; - labelAdditionalColor.DragEnter += labelAdditionalColor_DragEnter; + labelAdditionalColor.DragEnter += labelColor_DragEnter; // // labelColor // diff --git a/Trolleybus/Trolleybus/FormBusConfig.cs b/Trolleybus/Trolleybus/FormBusConfig.cs index 76da4e4..d5bea58 100644 --- a/Trolleybus/Trolleybus/FormBusConfig.cs +++ b/Trolleybus/Trolleybus/FormBusConfig.cs @@ -41,8 +41,8 @@ namespace ProjectTrolleybus { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Graphics gr = Graphics.FromImage(bmp); - _bus?.SetPosition(5, 5); - _bus?.DrawTransport(gr); + _bus?.SetPosition(5, 5); + _bus?.DrawTransport(gr); pictureBoxObject.Image = bmp; } @@ -82,7 +82,7 @@ namespace ProjectTrolleybus { case "labelSimple": _bus = new DrawingBus((int)numericUpDownSpeed.Value, - (int)numericUpDownWeight.Value, Color.White, _pictureWidth, _pictureHeight); + (int)numericUpDownWeight.Value, Color.White, _pictureWidth, _pictureHeight); break; case "labelAdvanced": _bus = new DrawingTrolleybus((int)numericUpDownSpeed.Value, @@ -113,18 +113,7 @@ namespace ProjectTrolleybus if (_bus == null || _bus.EntityBus == null) return; Color colorBody = (Color)e.Data.GetData(typeof(Color)); - if (_bus is DrawingTrolleybus == false) - { - _bus = new DrawingBus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, - colorBody, _pictureWidth, _pictureHeight); - } - else - { - _bus = new DrawingTrolleybus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, - colorBody, ((EntityTrolleybus)_bus.EntityBus).AdditionalColor, checkBoxRoga.Checked, - checkBoxBattery.Checked, _pictureWidth, _pictureHeight); - - } + _bus.EntityBus.ChangeColor(colorBody); DrawBus(); } @@ -145,23 +134,9 @@ namespace ProjectTrolleybus if (_bus == null || _bus.EntityBus == null || _bus is DrawingTrolleybus == false) return; Color colorAdditional = (Color)e.Data.GetData(typeof(Color)); - _bus = new DrawingTrolleybus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, - _bus.EntityBus.BodyColor, colorAdditional, checkBoxRoga.Checked, - checkBoxBattery.Checked, _pictureWidth, _pictureHeight); + ((EntityTrolleybus)_bus.EntityBus).ChangeAdditColor(colorAdditional); DrawBus(); } - - private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(typeof(Color))) - { - e.Effect = DragDropEffects.Copy; - } - else - { - e.Effect = DragDropEffects.None; - } - } } } -- 2.25.1