From 722d1769ac011b83b5844390e83d10a7137bdeda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Wed, 9 Nov 2022 19:07:16 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D0=B5=D0=B2,=20=D1=83=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B5=D0=B8=D1=81=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D0=BC=D1=8B=D1=85=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=B4=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormLocomotiveConfig.Designer.cs | 2 - .../Locomotives/FormLocomotiveConfig.cs | 70 ++++++++++++++++--- Locomotives/Locomotives/LocomotiveDelegate.cs | 4 ++ 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/Locomotives/Locomotives/FormLocomotiveConfig.Designer.cs b/Locomotives/Locomotives/FormLocomotiveConfig.Designer.cs index a98a487..6eab129 100644 --- a/Locomotives/Locomotives/FormLocomotiveConfig.Designer.cs +++ b/Locomotives/Locomotives/FormLocomotiveConfig.Designer.cs @@ -267,7 +267,6 @@ this.checkBoxHasFuelTank.TabIndex = 5; this.checkBoxHasFuelTank.Text = "Наличие топливного бака"; this.checkBoxHasFuelTank.UseVisualStyleBackColor = true; - this.checkBoxHasFuelTank.CheckedChanged += new System.EventHandler(this.CheckBoxexAdditionalElements_CheckedChanged); // // checkBoxHasPipe // @@ -278,7 +277,6 @@ this.checkBoxHasPipe.TabIndex = 4; this.checkBoxHasPipe.Text = "Наличие трубы"; this.checkBoxHasPipe.UseVisualStyleBackColor = true; - this.checkBoxHasPipe.CheckedChanged += new System.EventHandler(this.CheckBoxexAdditionalElements_CheckedChanged); // // numericUpDownWeight // diff --git a/Locomotives/Locomotives/FormLocomotiveConfig.cs b/Locomotives/Locomotives/FormLocomotiveConfig.cs index 2cb2ae7..39c8b44 100644 --- a/Locomotives/Locomotives/FormLocomotiveConfig.cs +++ b/Locomotives/Locomotives/FormLocomotiveConfig.cs @@ -1,9 +1,21 @@ namespace Locomotives { + /// + /// Форма создания объекта + /// public partial class FormLocomotiveConfig : Form { + /// + /// Переменная - выбранный локомотив + /// DrawningLocomotive _locomotive = null; + /// + /// Событие + /// private event LocomotiveDelegate EventAddLocomotive; + /// + /// Конструктор + /// public FormLocomotiveConfig() { InitializeComponent(); @@ -15,8 +27,12 @@ panelRed.MouseDown += PanelColor_MouseDown; panelWhite.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown; + //Лямбда-выражение для закрытия окна buttonCancel.Click += (sender, e) => Close(); } + /// + /// Отрисовка локомотива + /// private void DrawLocomotive() { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); @@ -25,6 +41,10 @@ _locomotive?.DrawTransport(gr); pictureBoxObject.Image = bmp; } + /// + /// Добавление события + /// + /// public void AddEvent(LocomotiveDelegate ev) { if (EventAddLocomotive == null) @@ -36,11 +56,20 @@ EventAddLocomotive += ev; } } + /// + /// Передаём информацию при нажатии на Label + /// + /// + /// private void LabelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy); } - + /// + /// Проверка получаемой информации + /// + /// + /// private void PanelObject_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.Text)) @@ -52,6 +81,11 @@ e.Effect = DragDropEffects.None; } } + /// + /// Действие при приёме получаемой информации + /// + /// + /// private void PanelObject_DragDrop(object sender, DragEventArgs e) { switch (e.Data.GetData(DataFormats.Text).ToString()) @@ -65,11 +99,20 @@ } DrawLocomotive(); } + /// + /// Отправляем цвет с панели + /// + /// + /// private void PanelColor_MouseDown(object sender, MouseEventArgs e) { (sender as Panel).DoDragDrop((sender as Panel).BackColor, DragDropEffects.Move | DragDropEffects.Copy); } - + /// + /// Проверка получаемой информации + /// + /// + /// private void LabelColor_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(Color))) @@ -81,13 +124,21 @@ e.Effect= DragDropEffects.None; } } - + /// + /// Принимаем основной цвет + /// + /// + /// private void LabelColor_DragDrop(object sender, DragEventArgs e) { _locomotive.Locomotive.BodyColor = (Color)e.Data.GetData(typeof(Color)); DrawLocomotive(); } - + /// + /// Принимаем дополнительный цвет + /// + /// + /// private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e) { if (_locomotive.Locomotive is EntityWarmlyLocomotive warmlyLocomotive) @@ -96,16 +147,15 @@ } DrawLocomotive(); } - + /// + /// Добавление локомотива + /// + /// + /// private void ButtonOk_Click(object sender, EventArgs e) { EventAddLocomotive?.Invoke(_locomotive); Close(); } - - private void CheckBoxexAdditionalElements_CheckedChanged(object sender, EventArgs e) - { - DrawLocomotive(); - } } } diff --git a/Locomotives/Locomotives/LocomotiveDelegate.cs b/Locomotives/Locomotives/LocomotiveDelegate.cs index 894767b..475f02f 100644 --- a/Locomotives/Locomotives/LocomotiveDelegate.cs +++ b/Locomotives/Locomotives/LocomotiveDelegate.cs @@ -1,4 +1,8 @@ namespace Locomotives { + /// + /// Делегат для передачи объекта-локомотива + /// + /// public delegate void LocomotiveDelegate(DrawningLocomotive locomotive); }