diff --git a/lab1/DrawingObjects/DrawingElectricLocomotiv.cs b/lab1/DrawingObjects/DrawingElectricLocomotiv.cs index 65935d8..e0b5200 100644 --- a/lab1/DrawingObjects/DrawingElectricLocomotiv.cs +++ b/lab1/DrawingObjects/DrawingElectricLocomotiv.cs @@ -4,15 +4,24 @@ namespace ElectricLocomotive; public class DrawingElectricLocomotiv : DrawingLocomotiv { - public DrawingElectricLocomotiv(int speed, double weight, int width, int height, Color mainColor, Color dopColor, Color batteryColor, Color rogaColor) : base(speed, weight, width, + private bool isBattery; + private bool isRoga; + public DrawingElectricLocomotiv(bool isBattery, bool isRoga, int speed, double weight, int width, int height, Color mainColor, Color dopColor, Color batteryColor, Color rogaColor) : base(speed, weight, width, height, mainColor, dopColor) { + this.isBattery = isBattery; + this.isRoga = isRoga; if (EntityLocomotiv != null) { EntityLocomotiv = new EntityElectricLocomotiv(speed, weight, batteryColor, rogaColor, mainColor, dopColor); } } + public void ChangeAddColor(Color col) + { + ((EntityElectricLocomotiv)EntityLocomotiv).BatteryColor = col; + ((EntityElectricLocomotiv)EntityLocomotiv).RogaColor = col; + } public override void DrawLoco(Graphics g) { if (EntityLocomotiv == null) return; @@ -20,11 +29,16 @@ public class DrawingElectricLocomotiv : DrawingLocomotiv if (EntityLocomotiv is not EntityElectricLocomotiv electricLocomotiv) return; SolidBrush batteryBrush = new(electricLocomotiv.BatteryColor); Pen rogaPen = new(electricLocomotiv.RogaColor); - //Roga - g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2, _startPosY + 30), new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15)); - g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15), new Point(_startPosX + _vehicleWidth / 2, _startPosY)); - //battery - Point[] batteryPoints = { new Point(_startPosX + _vehicleWidth - 10,_startPosY + _vehicleHeight - 25), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 20), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 55), new Point(_startPosX + _vehicleWidth - 10, _startPosY + _vehicleHeight - 50) }; - g.FillPolygon(batteryBrush, batteryPoints); + if (this.isRoga) + { + g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2, _startPosY + 30), new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15)); + g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15), new Point(_startPosX + _vehicleWidth / 2, _startPosY)); + } + + if (this.isBattery) + { + Point[] batteryPoints = { new Point(_startPosX + _vehicleWidth - 10,_startPosY + _vehicleHeight - 25), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 20), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 55), new Point(_startPosX + _vehicleWidth - 10, _startPosY + _vehicleHeight - 50) }; + g.FillPolygon(batteryBrush, batteryPoints); + } } } \ No newline at end of file diff --git a/lab1/DrawingObjects/DrawingLocomotiv.cs b/lab1/DrawingObjects/DrawingLocomotiv.cs index 049598d..83be214 100644 --- a/lab1/DrawingObjects/DrawingLocomotiv.cs +++ b/lab1/DrawingObjects/DrawingLocomotiv.cs @@ -41,6 +41,14 @@ namespace ElectricLocomotive _pictureHeight = height; EntityLocomotiv = new EntityLocomotiv(speed, weight, mainColor, dopColor); } + + public void ChangeColor(Color col) + { + if (EntityLocomotiv == null) + return; + EntityLocomotiv.ColorBody = col; + EntityLocomotiv.ColorWindow = col; + } public bool CanMove(DirectionType direction) { if (EntityLocomotiv == null) @@ -96,6 +104,11 @@ namespace ElectricLocomotive break; } } + public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight) + { + _pictureHeight = pictureBoxHeight; + _pictureWidth = pictureBoxWidth; + } public virtual void DrawLoco(Graphics g) { if (EntityLocomotiv == null) return; diff --git a/lab1/Entities/EntityElectricLocomotiv.cs b/lab1/Entities/EntityElectricLocomotiv.cs index 5314e0f..28d0d89 100644 --- a/lab1/Entities/EntityElectricLocomotiv.cs +++ b/lab1/Entities/EntityElectricLocomotiv.cs @@ -2,8 +2,8 @@ public class EntityElectricLocomotiv : EntityLocomotiv { - public Color BatteryColor { get; private set; } - public Color RogaColor { get; private set; } + public Color BatteryColor { get; set; } + public Color RogaColor { get; set; } public EntityElectricLocomotiv(int speed,double weight, Color batteryColor, Color rogaColor, Color mainColor, Color dopColor) : base(speed, weight, mainColor, dopColor) { BatteryColor = batteryColor; diff --git a/lab1/Entities/EntityLocomotiv.cs b/lab1/Entities/EntityLocomotiv.cs index 5a32b76..17d0b17 100644 --- a/lab1/Entities/EntityLocomotiv.cs +++ b/lab1/Entities/EntityLocomotiv.cs @@ -9,8 +9,8 @@ namespace ElectricLocomotive { public class EntityLocomotiv { - public int Speed { get; private set; } - public double Weight { get; private set; } + public int Speed { get; set; } + public double Weight { get; set; } public double Step => (double)Speed * 100 / Weight; public Color ColorBody = Color.Black; public Color ColorWindow = Color.Blue; diff --git a/lab1/FormLocoConfig.Designer.cs b/lab1/FormLocoConfig.Designer.cs new file mode 100644 index 0000000..7f8bd81 --- /dev/null +++ b/lab1/FormLocoConfig.Designer.cs @@ -0,0 +1,350 @@ +namespace ElectricLocomotive { + partial class FormLocoConfig { + /// + /// 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() { + mainGroupBox = new GroupBox(); + checkBoxBattery = new CheckBox(); + checkBoxRoga = new CheckBox(); + labelAdvanced = new Label(); + labelSimple = new Label(); + groupBoxColors = new GroupBox(); + panelPurple = new Panel(); + panelYellow = new Panel(); + panelBlack = new Panel(); + panelBlue = new Panel(); + panelGray = new Panel(); + panelGreen = new Panel(); + panelWhite = new Panel(); + panelRed = new Panel(); + numericUpDownWeight = new NumericUpDown(); + numericUpDownSpeed = new NumericUpDown(); + label2 = new Label(); + label1 = new Label(); + rightPanel = new Panel(); + labelAddColor = new Label(); + labelColor = new Label(); + pictureBox = new PictureBox(); + buttonAdd = new Button(); + buttonCancel = new Button(); + mainGroupBox.SuspendLayout(); + groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + rightPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // mainGroupBox + // + mainGroupBox.Controls.Add(checkBoxBattery); + mainGroupBox.Controls.Add(checkBoxRoga); + mainGroupBox.Controls.Add(labelAdvanced); + mainGroupBox.Controls.Add(labelSimple); + mainGroupBox.Controls.Add(groupBoxColors); + mainGroupBox.Controls.Add(numericUpDownWeight); + mainGroupBox.Controls.Add(numericUpDownSpeed); + mainGroupBox.Controls.Add(label2); + mainGroupBox.Controls.Add(label1); + mainGroupBox.Location = new Point(12, 12); + mainGroupBox.Name = "mainGroupBox"; + mainGroupBox.Size = new Size(656, 289); + mainGroupBox.TabIndex = 0; + mainGroupBox.TabStop = false; + mainGroupBox.Text = "Параметры"; + // + // checkBoxBattery + // + checkBoxBattery.AutoSize = true; + checkBoxBattery.Location = new Point(25, 194); + checkBoxBattery.Name = "checkBoxBattery"; + checkBoxBattery.Size = new Size(215, 24); + checkBoxBattery.TabIndex = 8; + checkBoxBattery.Text = "Признак наличия батарей"; + checkBoxBattery.UseVisualStyleBackColor = true; + // + // checkBoxRoga + // + checkBoxRoga.AutoSize = true; + checkBoxRoga.Location = new Point(25, 150); + checkBoxRoga.Name = "checkBoxRoga"; + checkBoxRoga.Size = new Size(199, 24); + checkBoxRoga.TabIndex = 7; + checkBoxRoga.Text = "Признак наличия рогов"; + checkBoxRoga.UseVisualStyleBackColor = true; + // + // labelAdvanced + // + labelAdvanced.BorderStyle = BorderStyle.FixedSingle; + labelAdvanced.Location = new Point(498, 231); + labelAdvanced.Name = "labelAdvanced"; + labelAdvanced.Size = new Size(141, 44); + labelAdvanced.TabIndex = 6; + labelAdvanced.Text = "Продвинутый"; + labelAdvanced.TextAlign = ContentAlignment.MiddleCenter; + // + // labelSimple + // + labelSimple.BorderStyle = BorderStyle.FixedSingle; + labelSimple.Location = new Point(323, 231); + labelSimple.Name = "labelSimple"; + labelSimple.Size = new Size(141, 44); + labelSimple.TabIndex = 5; + labelSimple.Text = "Простой"; + labelSimple.TextAlign = ContentAlignment.MiddleCenter; + labelSimple.MouseDown += labelSimple_MouseDown; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelPurple); + groupBoxColors.Controls.Add(panelYellow); + groupBoxColors.Controls.Add(panelBlack); + groupBoxColors.Controls.Add(panelBlue); + groupBoxColors.Controls.Add(panelGray); + groupBoxColors.Controls.Add(panelGreen); + groupBoxColors.Controls.Add(panelWhite); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Location = new Point(323, 26); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(316, 192); + groupBoxColors.TabIndex = 4; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(239, 114); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(60, 56); + panelPurple.TabIndex = 3; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(239, 38); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(60, 56); + panelYellow.TabIndex = 1; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(159, 114); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(60, 56); + panelBlack.TabIndex = 4; + // + // panelBlue + // + panelBlue.BackColor = Color.Navy; + panelBlue.Location = new Point(159, 38); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(60, 56); + panelBlue.TabIndex = 1; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(81, 114); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(60, 56); + panelGray.TabIndex = 5; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(81, 38); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(60, 56); + panelGreen.TabIndex = 1; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(6, 114); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(60, 56); + panelWhite.TabIndex = 2; + // + // panelRed + // + panelRed.BackColor = Color.FromArgb(192, 0, 0); + panelRed.Location = new Point(6, 38); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(60, 56); + panelRed.TabIndex = 0; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(113, 82); + 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(75, 27); + numericUpDownWeight.TabIndex = 3; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(113, 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(75, 27); + numericUpDownSpeed.TabIndex = 2; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(19, 82); + label2.Name = "label2"; + label2.Size = new Size(33, 20); + label2.TabIndex = 1; + label2.Text = "Вес"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(19, 42); + label1.Name = "label1"; + label1.Size = new Size(73, 20); + label1.TabIndex = 0; + label1.Text = "Скорость"; + // + // rightPanel + // + rightPanel.AllowDrop = true; + rightPanel.Controls.Add(labelAddColor); + rightPanel.Controls.Add(labelColor); + rightPanel.Controls.Add(pictureBox); + rightPanel.Location = new Point(689, 21); + rightPanel.Name = "rightPanel"; + rightPanel.Size = new Size(348, 234); + rightPanel.TabIndex = 1; + rightPanel.DragDrop += rightPanel_DragDrop; + rightPanel.DragEnter += rightPanel_DragEnter; + // + // labelAddColor + // + labelAddColor.AllowDrop = true; + labelAddColor.BorderStyle = BorderStyle.FixedSingle; + labelAddColor.Location = new Point(184, 12); + labelAddColor.Name = "labelAddColor"; + labelAddColor.Size = new Size(149, 40); + labelAddColor.TabIndex = 2; + labelAddColor.Text = "Доп. Цвет"; + labelAddColor.TextAlign = ContentAlignment.MiddleCenter; + labelAddColor.DragDrop += labelAddColor_DragDrop; + labelAddColor.DragEnter += labelAddColor_DragEnter; + // + // labelColor + // + labelColor.AllowDrop = true; + labelColor.BorderStyle = BorderStyle.FixedSingle; + labelColor.Location = new Point(16, 12); + labelColor.Name = "labelColor"; + labelColor.Size = new Size(149, 40); + labelColor.TabIndex = 1; + labelColor.Text = "Цвет"; + labelColor.TextAlign = ContentAlignment.MiddleCenter; + labelColor.DragDrop += labelColor_DragDrop; + labelColor.DragEnter += labelColor_DragEnter; + // + // pictureBox + // + pictureBox.Location = new Point(16, 55); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(317, 165); + pictureBox.TabIndex = 0; + pictureBox.TabStop = false; + // + // buttonAdd + // + buttonAdd.Location = new Point(689, 266); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(165, 35); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(872, 266); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(165, 35); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormLocoConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1053, 313); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(rightPanel); + Controls.Add(mainGroupBox); + Name = "FormLocoConfig"; + Text = "Создание объекта"; + mainGroupBox.ResumeLayout(false); + mainGroupBox.PerformLayout(); + groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + rightPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox mainGroupBox; + private Label label1; + private Label label2; + private NumericUpDown numericUpDownSpeed; + private Label labelSimple; + private GroupBox groupBoxColors; + private NumericUpDown numericUpDownWeight; + private Label labelAdvanced; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private CheckBox checkBoxBattery; + private CheckBox checkBoxRoga; + private Panel rightPanel; + private Label labelAddColor; + private Label labelColor; + private PictureBox pictureBox; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/lab1/FormLocoConfig.cs b/lab1/FormLocoConfig.cs new file mode 100644 index 0000000..2439371 --- /dev/null +++ b/lab1/FormLocoConfig.cs @@ -0,0 +1,126 @@ +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 ElectricLocomotive { + public partial class FormLocoConfig : Form { + DrawingLocomotiv? _loco = null; + private event Action? EventAddLoco; + public void AddEvent(Action ev) { + if (EventAddLoco == null) { + EventAddLoco = ev; + } + else { + EventAddLoco += ev; + } + } + public FormLocoConfig() { + InitializeComponent(); + panelBlack.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelRed.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + panelGray.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelWhite.MouseDown += PanelColor_MouseDown; + labelSimple.MouseDown += LabelObject_MouseDown; + labelAdvanced.MouseDown += LabelObject_MouseDown; + buttonCancel.Click += (s, e) => Close(); + } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, +DragDropEffects.Move | DragDropEffects.Copy); + } + private void LabelObject_MouseDown(object sender, MouseEventArgs e) { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); + } + private void DrawLoco() { + Bitmap bmp = new(pictureBox.Width, pictureBox.Height); + Graphics gr = Graphics.FromImage(bmp); + _loco?.SetPosition(5, 5); + _loco?.DrawLoco(gr); + pictureBox.Image = bmp; + } + + + private void labelSimple_MouseDown(object sender, MouseEventArgs e) { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, + DragDropEffects.Move | DragDropEffects.Copy); + } + + private void rightPanel_DragEnter(object sender, DragEventArgs e) { + + if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) { + e.Effect = DragDropEffects.Copy; + } + else { + e.Effect = DragDropEffects.None; + } + } + + private void rightPanel_DragDrop(object sender, DragEventArgs e) { + switch (e.Data?.GetData(DataFormats.Text).ToString()) { + case "labelSimple": + _loco = new DrawingLocomotiv((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, pictureBox.Width, + pictureBox.Height, Color.Black, Color.Yellow); + break; + case "labelAdvanced": + _loco = new DrawingElectricLocomotiv(checkBoxRoga.Checked, checkBoxBattery.Checked, + (int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, pictureBox.Width, + pictureBox.Height, Color.Black, Color.Yellow, Color.Aqua, Color.Black); + break; + } + labelColor.BackColor = Color.Empty; + labelAddColor.BackColor = Color.Empty; + DrawLoco(); + } + + private void buttonAdd_Click(object sender, EventArgs e) { + EventAddLoco?.Invoke(_loco); + Close(); + } + + + private void labelColor_DragEnter(object sender, DragEventArgs e) { + if (e.Data.GetDataPresent(typeof(Color))) { + e.Effect = DragDropEffects.Copy; + } + else { + e.Effect = DragDropEffects.None; + } + } + + private void labelColor_DragDrop(object sender, DragEventArgs e) { + if (_loco == null) + return; + labelColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + _loco.ChangeColor(labelColor.BackColor); + DrawLoco(); + } + + private void labelAddColor_DragEnter(object sender, DragEventArgs e) { + if (e.Data.GetDataPresent(typeof(Color))) { + e.Effect = DragDropEffects.Copy; + } + else { + e.Effect = DragDropEffects.None; + } + } + + private void labelAddColor_DragDrop(object sender, DragEventArgs e) { + if ((_loco == null) || (_loco is DrawingElectricLocomotiv == false)) + return; + labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + ((DrawingElectricLocomotiv)_loco).ChangeAddColor(labelAddColor.BackColor); + DrawLoco(); + } + } +} diff --git a/lab1/FormLocoConfig.resx b/lab1/FormLocoConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/lab1/FormLocoConfig.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/lab1/FormLocomotiv.cs b/lab1/FormLocomotiv.cs index e872ea1..bcbf3bf 100644 --- a/lab1/FormLocomotiv.cs +++ b/lab1/FormLocomotiv.cs @@ -43,7 +43,7 @@ namespace ElectricLocomotive { if (dialog.ShowDialog() == DialogResult.OK) dopColor = dialog.Color; - _drawingLocomotiv = new DrawingElectricLocomotiv(random.Next(100, 300), random.Next(1000, 3000), locoBox.Width, locoBox.Height, color, dopColor, batteryColor, rogaColor); + _drawingLocomotiv = new DrawingElectricLocomotiv(true, true, random.Next(100, 300), random.Next(1000, 3000), locoBox.Width, locoBox.Height, color, dopColor, batteryColor, rogaColor); _drawingLocomotiv.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } diff --git a/lab1/FormLocomotivCollection.cs b/lab1/FormLocomotivCollection.cs index 668f858..1020bd1 100644 --- a/lab1/FormLocomotivCollection.cs +++ b/lab1/FormLocomotivCollection.cs @@ -30,17 +30,22 @@ public partial class FormLocomotivCollection : Form { if (obj == null) { return; } - FormLocomotiv form = new(); - if (form.ShowDialog() == DialogResult.OK) { - if (obj + form.SelectedLocomotiv) { + FormLocoConfig form = new(); + form.Show(); + Action? monorailDelegate = new((m) => { + bool q = (obj + m); + if (q) + { MessageBox.Show("Объект добавлен"); + m.ChangePictureBoxSize(collectionPictureBox.Width, collectionPictureBox.Height); collectionPictureBox.Image = obj.ShowLocos(); } - else { + else + { MessageBox.Show("Не удалось добавить объект"); } - - } + }); + form.AddEvent(monorailDelegate); } private void deleteLoco_Click(object sender, EventArgs e) { if (storageListBox.SelectedIndex == -1) {