From 76d527f8d11793ca8d23a09a4a93c0b92912ebc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Mon, 6 Nov 2023 18:59:42 +0400 Subject: [PATCH 1/9] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D0=BD=D0=B0=D0=B4=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D0=B9=205,=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/FormBoatConfig.Designer.cs | 46 +++++++++++++++ Sailboat/Sailboat/FormBoatConfig.cs | 20 +++++++ Sailboat/Sailboat/FormBoatConfig.resx | 60 ++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 Sailboat/Sailboat/FormBoatConfig.Designer.cs create mode 100644 Sailboat/Sailboat/FormBoatConfig.cs create mode 100644 Sailboat/Sailboat/FormBoatConfig.resx diff --git a/Sailboat/Sailboat/FormBoatConfig.Designer.cs b/Sailboat/Sailboat/FormBoatConfig.Designer.cs new file mode 100644 index 0000000..895b8b5 --- /dev/null +++ b/Sailboat/Sailboat/FormBoatConfig.Designer.cs @@ -0,0 +1,46 @@ +namespace Sailboat +{ + partial class FormBoatConfig + { + /// + /// 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() + { + this.SuspendLayout(); + // + // FormBoatConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Name = "FormBoatConfig"; + this.Text = "Создание объекта"; + this.ResumeLayout(false); + + } + + #endregion + } +} \ No newline at end of file diff --git a/Sailboat/Sailboat/FormBoatConfig.cs b/Sailboat/Sailboat/FormBoatConfig.cs new file mode 100644 index 0000000..99708c6 --- /dev/null +++ b/Sailboat/Sailboat/FormBoatConfig.cs @@ -0,0 +1,20 @@ +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 Sailboat +{ + public partial class FormBoatConfig : Form + { + public FormBoatConfig() + { + InitializeComponent(); + } + } +} diff --git a/Sailboat/Sailboat/FormBoatConfig.resx b/Sailboat/Sailboat/FormBoatConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Sailboat/Sailboat/FormBoatConfig.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 -- 2.25.1 From 5ade5f7e0854b531b189706a5cc95345b68a99ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Mon, 6 Nov 2023 20:40:05 +0400 Subject: [PATCH 2/9] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0=20=D1=81=D0=BB=D0=B5=D1=82=D0=B5=D0=B2=D1=88?= =?UTF-8?q?=D1=83=D1=8E=20=D1=84=D0=BE=D1=80=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatDelegate.cs | 11 + Sailboat/Sailboat/FormBoatConfig.Designer.cs | 326 ++++++++++++++++++- Sailboat/Sailboat/FormBoatConfig.cs | 94 ++++++ 3 files changed, 430 insertions(+), 1 deletion(-) create mode 100644 Sailboat/Sailboat/BoatDelegate.cs diff --git a/Sailboat/Sailboat/BoatDelegate.cs b/Sailboat/Sailboat/BoatDelegate.cs new file mode 100644 index 0000000..377892f --- /dev/null +++ b/Sailboat/Sailboat/BoatDelegate.cs @@ -0,0 +1,11 @@ +using Sailboat.DrawingObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sailboat +{ + internal delegate void BoatDelegate(DrawingBoat boat); +} diff --git a/Sailboat/Sailboat/FormBoatConfig.Designer.cs b/Sailboat/Sailboat/FormBoatConfig.Designer.cs index 895b8b5..a1bac2b 100644 --- a/Sailboat/Sailboat/FormBoatConfig.Designer.cs +++ b/Sailboat/Sailboat/FormBoatConfig.Designer.cs @@ -28,19 +28,343 @@ /// private void InitializeComponent() { + this.groupBoxColors = new System.Windows.Forms.GroupBox(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelGray = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.groupBoxParameters = new System.Windows.Forms.GroupBox(); + this.labelSpeed = new System.Windows.Forms.Label(); + this.labelWeight = new System.Windows.Forms.Label(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.checkBoxHull = new System.Windows.Forms.CheckBox(); + this.checkBoxSail = new System.Windows.Forms.CheckBox(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.labelModifiedObject = new System.Windows.Forms.Label(); + this.panel1 = new System.Windows.Forms.Panel(); + this.labelAddColor = new System.Windows.Forms.Label(); + this.labelColor = new System.Windows.Forms.Label(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxColors.SuspendLayout(); + this.groupBoxParameters.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); this.SuspendLayout(); // + // groupBoxColors + // + this.groupBoxColors.Controls.Add(this.panelPurple); + this.groupBoxColors.Controls.Add(this.panelYellow); + this.groupBoxColors.Controls.Add(this.panelBlack); + this.groupBoxColors.Controls.Add(this.panelBlue); + this.groupBoxColors.Controls.Add(this.panelGray); + this.groupBoxColors.Controls.Add(this.panelWhite); + this.groupBoxColors.Controls.Add(this.panelGreen); + this.groupBoxColors.Controls.Add(this.panelRed); + this.groupBoxColors.Location = new System.Drawing.Point(345, 26); + this.groupBoxColors.Name = "groupBoxColors"; + this.groupBoxColors.Size = new System.Drawing.Size(284, 179); + this.groupBoxColors.TabIndex = 0; + this.groupBoxColors.TabStop = false; + this.groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.Location = new System.Drawing.Point(217, 101); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(50, 50); + this.panelPurple.TabIndex = 7; + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(217, 35); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(50, 50); + this.panelYellow.TabIndex = 3; + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(150, 101); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(50, 50); + this.panelBlack.TabIndex = 6; + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(150, 35); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(50, 50); + this.panelBlue.TabIndex = 2; + // + // panelGray + // + this.panelGray.BackColor = System.Drawing.Color.Gray; + this.panelGray.Location = new System.Drawing.Point(83, 101); + this.panelGray.Name = "panelGray"; + this.panelGray.Size = new System.Drawing.Size(50, 50); + this.panelGray.TabIndex = 5; + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(16, 101); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(50, 50); + this.panelWhite.TabIndex = 4; + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.Green; + this.panelGreen.Location = new System.Drawing.Point(83, 35); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(50, 50); + this.panelGreen.TabIndex = 1; + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(16, 35); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(50, 50); + this.panelRed.TabIndex = 0; + // + // groupBoxParameters + // + this.groupBoxParameters.Controls.Add(this.labelModifiedObject); + this.groupBoxParameters.Controls.Add(this.labelSimpleObject); + this.groupBoxParameters.Controls.Add(this.checkBoxSail); + this.groupBoxParameters.Controls.Add(this.checkBoxHull); + this.groupBoxParameters.Controls.Add(this.numericUpDownWeight); + this.groupBoxParameters.Controls.Add(this.numericUpDownSpeed); + this.groupBoxParameters.Controls.Add(this.labelWeight); + this.groupBoxParameters.Controls.Add(this.labelSpeed); + this.groupBoxParameters.Controls.Add(this.groupBoxColors); + this.groupBoxParameters.Location = new System.Drawing.Point(12, 12); + this.groupBoxParameters.Name = "groupBoxParameters"; + this.groupBoxParameters.Size = new System.Drawing.Size(640, 285); + this.groupBoxParameters.TabIndex = 1; + this.groupBoxParameters.TabStop = false; + this.groupBoxParameters.Text = "Параметры"; + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(25, 36); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(76, 20); + this.labelSpeed.TabIndex = 1; + this.labelSpeed.Text = "Скорость:"; + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(25, 79); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(36, 20); + this.labelWeight.TabIndex = 2; + this.labelWeight.Text = "Вес:"; + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(118, 34); + this.numericUpDownSpeed.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownSpeed.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(141, 27); + this.numericUpDownSpeed.TabIndex = 3; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(118, 77); + this.numericUpDownWeight.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownWeight.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(141, 27); + this.numericUpDownWeight.TabIndex = 4; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // checkBoxHull + // + this.checkBoxHull.AutoSize = true; + this.checkBoxHull.Location = new System.Drawing.Point(6, 127); + this.checkBoxHull.Name = "checkBoxHull"; + this.checkBoxHull.Size = new System.Drawing.Size(237, 24); + this.checkBoxHull.TabIndex = 5; + this.checkBoxHull.Text = "Наличие усиленного корпуса"; + this.checkBoxHull.UseVisualStyleBackColor = true; + // + // checkBoxSail + // + this.checkBoxSail.AutoSize = true; + this.checkBoxSail.Location = new System.Drawing.Point(6, 168); + this.checkBoxSail.Name = "checkBoxSail"; + this.checkBoxSail.Size = new System.Drawing.Size(169, 24); + this.checkBoxSail.TabIndex = 6; + this.checkBoxSail.Text = "Наличие парусника"; + this.checkBoxSail.UseVisualStyleBackColor = true; + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(345, 225); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(140, 40); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // labelModifiedObject + // + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(489, 225); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(140, 40); + this.labelModifiedObject.TabIndex = 8; + this.labelModifiedObject.Text = "Продвинутый"; + this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // panel1 + // + this.panel1.Controls.Add(this.pictureBoxObject); + this.panel1.Controls.Add(this.labelAddColor); + this.panel1.Controls.Add(this.labelColor); + this.panel1.Location = new System.Drawing.Point(658, 12); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(362, 330); + this.panel1.TabIndex = 2; + // + // labelAddColor + // + this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAddColor.Location = new System.Drawing.Point(182, 16); + this.labelAddColor.Name = "labelAddColor"; + this.labelAddColor.Size = new System.Drawing.Size(140, 40); + this.labelAddColor.TabIndex = 10; + this.labelAddColor.Text = "Доп. цвет"; + this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // labelColor + // + this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelColor.Location = new System.Drawing.Point(38, 16); + this.labelColor.Name = "labelColor"; + this.labelColor.Size = new System.Drawing.Size(140, 40); + this.labelColor.TabIndex = 9; + this.labelColor.Text = "Цвет"; + this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(3, 61); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(356, 266); + this.pictureBoxObject.TabIndex = 11; + this.pictureBoxObject.TabStop = false; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(694, 348); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(140, 40); + this.buttonAdd.TabIndex = 3; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(840, 348); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(140, 40); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // // FormBoatConfig // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(1032, 394); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.panel1); + this.Controls.Add(this.groupBoxParameters); this.Name = "FormBoatConfig"; this.Text = "Создание объекта"; + this.groupBoxColors.ResumeLayout(false); + this.groupBoxParameters.ResumeLayout(false); + this.groupBoxParameters.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); this.ResumeLayout(false); } #endregion + + private GroupBox groupBoxColors; + 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 GroupBox groupBoxParameters; + private Label labelModifiedObject; + private Label labelSimpleObject; + private CheckBox checkBoxSail; + private CheckBox checkBoxHull; + private NumericUpDown numericUpDownWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelWeight; + private Label labelSpeed; + private Panel panel1; + private PictureBox pictureBoxObject; + private Label labelAddColor; + private Label labelColor; + private Button buttonAdd; + private Button buttonCancel; } } \ No newline at end of file diff --git a/Sailboat/Sailboat/FormBoatConfig.cs b/Sailboat/Sailboat/FormBoatConfig.cs index 99708c6..ab8a453 100644 --- a/Sailboat/Sailboat/FormBoatConfig.cs +++ b/Sailboat/Sailboat/FormBoatConfig.cs @@ -8,13 +8,107 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Sailboat.DrawingObjects; +using Sailboat.Generics; +using Sailboat.MovementStrategy; + namespace Sailboat { public partial class FormBoatConfig : Form { + /// + /// Переменная-выбранная машина + /// + DrawingBoat? _boat = null; + /// + /// Событие + /// + private event BoatDelegate? EventAddBoat; + /// + /// Конструктор + /// public FormBoatConfig() { 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); + _boat?.SetPosition(5, 5); + _boat?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + public void AddEvent(BoatDelegate ev) + { + if (EventAddBoat == null) + { + EventAddBoat = ev; + } + else + { + EventAddBoat += ev; + } + } + 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 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": + _boat = new DrawingBoat((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _boat = new DrawingSailboat((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxHull.Checked, + checkBoxSail.Checked, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + } + DrawCar(); + } + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddBoat?.Invoke(_boat); + Close(); } } } -- 2.25.1 From b700173d7b96e5b3ea3726398df2eac04afe359c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 7 Nov 2023 22:22:14 +0400 Subject: [PATCH 3/9] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B4=D0=BE=D0=BB=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=B4=20=D0=BB=D0=B0=D0=B1=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/FormBoatCollection.cs | 7 + Sailboat/Sailboat/FormBoatConfig.Designer.cs | 228 ++++++++++--------- Sailboat/Sailboat/FormBoatConfig.cs | 20 +- 3 files changed, 130 insertions(+), 125 deletions(-) diff --git a/Sailboat/Sailboat/FormBoatCollection.cs b/Sailboat/Sailboat/FormBoatCollection.cs index 5510193..ea847bb 100644 --- a/Sailboat/Sailboat/FormBoatCollection.cs +++ b/Sailboat/Sailboat/FormBoatCollection.cs @@ -48,6 +48,13 @@ namespace Sailboat } private void buttonAddBoat_Click(object sender, EventArgs e) + { + var formBoatConfig = new FormBoatConfig(); + formBoatConfig.AddEvent(AddBoat); + formBoatConfig.Show(); + } + + private void AddBoat(DrawingBoat drawingBoat) { if (listBoxStorages.SelectedIndex == -1) { diff --git a/Sailboat/Sailboat/FormBoatConfig.Designer.cs b/Sailboat/Sailboat/FormBoatConfig.Designer.cs index a1bac2b..7a6254c 100644 --- a/Sailboat/Sailboat/FormBoatConfig.Designer.cs +++ b/Sailboat/Sailboat/FormBoatConfig.Designer.cs @@ -38,25 +38,25 @@ this.panelGreen = new System.Windows.Forms.Panel(); this.panelRed = new System.Windows.Forms.Panel(); this.groupBoxParameters = new System.Windows.Forms.GroupBox(); - this.labelSpeed = new System.Windows.Forms.Label(); - this.labelWeight = new System.Windows.Forms.Label(); - this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); - this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); - this.checkBoxHull = new System.Windows.Forms.CheckBox(); - this.checkBoxSail = new System.Windows.Forms.CheckBox(); - this.labelSimpleObject = new System.Windows.Forms.Label(); this.labelModifiedObject = new System.Windows.Forms.Label(); - this.panel1 = new System.Windows.Forms.Panel(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.checkBoxSail = new System.Windows.Forms.CheckBox(); + this.checkBoxHull = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.labelWeight = new System.Windows.Forms.Label(); + this.labelSpeed = new System.Windows.Forms.Label(); + this.panelObject = new System.Windows.Forms.Panel(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); this.labelAddColor = new System.Windows.Forms.Label(); this.labelColor = new System.Windows.Forms.Label(); - this.pictureBoxObject = new System.Windows.Forms.PictureBox(); - this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonOk = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.groupBoxColors.SuspendLayout(); this.groupBoxParameters.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); - this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + this.panelObject.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); this.SuspendLayout(); // @@ -84,6 +84,7 @@ this.panelPurple.Name = "panelPurple"; this.panelPurple.Size = new System.Drawing.Size(50, 50); this.panelPurple.TabIndex = 7; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelYellow // @@ -92,6 +93,7 @@ this.panelYellow.Name = "panelYellow"; this.panelYellow.Size = new System.Drawing.Size(50, 50); this.panelYellow.TabIndex = 3; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelBlack // @@ -100,6 +102,7 @@ this.panelBlack.Name = "panelBlack"; this.panelBlack.Size = new System.Drawing.Size(50, 50); this.panelBlack.TabIndex = 6; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelBlue // @@ -108,6 +111,7 @@ this.panelBlue.Name = "panelBlue"; this.panelBlue.Size = new System.Drawing.Size(50, 50); this.panelBlue.TabIndex = 2; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelGray // @@ -116,6 +120,7 @@ this.panelGray.Name = "panelGray"; this.panelGray.Size = new System.Drawing.Size(50, 50); this.panelGray.TabIndex = 5; + this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelWhite // @@ -124,6 +129,7 @@ this.panelWhite.Name = "panelWhite"; this.panelWhite.Size = new System.Drawing.Size(50, 50); this.panelWhite.TabIndex = 4; + this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelGreen // @@ -132,6 +138,7 @@ this.panelGreen.Name = "panelGreen"; this.panelGreen.Size = new System.Drawing.Size(50, 50); this.panelGreen.TabIndex = 1; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelRed // @@ -140,6 +147,7 @@ this.panelRed.Name = "panelRed"; this.panelRed.Size = new System.Drawing.Size(50, 50); this.panelRed.TabIndex = 0; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // groupBoxParameters // @@ -159,45 +167,47 @@ this.groupBoxParameters.TabStop = false; this.groupBoxParameters.Text = "Параметры"; // - // labelSpeed + // labelModifiedObject // - this.labelSpeed.AutoSize = true; - this.labelSpeed.Location = new System.Drawing.Point(25, 36); - this.labelSpeed.Name = "labelSpeed"; - this.labelSpeed.Size = new System.Drawing.Size(76, 20); - this.labelSpeed.TabIndex = 1; - this.labelSpeed.Text = "Скорость:"; + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(489, 225); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(140, 40); + this.labelModifiedObject.TabIndex = 8; + this.labelModifiedObject.Text = "Продвинутый"; + this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); // - // labelWeight + // labelSimpleObject // - this.labelWeight.AutoSize = true; - this.labelWeight.Location = new System.Drawing.Point(25, 79); - this.labelWeight.Name = "labelWeight"; - this.labelWeight.Size = new System.Drawing.Size(36, 20); - this.labelWeight.TabIndex = 2; - this.labelWeight.Text = "Вес:"; + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(345, 225); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(140, 40); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); // - // numericUpDownSpeed + // checkBoxSail // - this.numericUpDownSpeed.Location = new System.Drawing.Point(118, 34); - this.numericUpDownSpeed.Maximum = new decimal(new int[] { - 1000, - 0, - 0, - 0}); - this.numericUpDownSpeed.Minimum = new decimal(new int[] { - 100, - 0, - 0, - 0}); - this.numericUpDownSpeed.Name = "numericUpDownSpeed"; - this.numericUpDownSpeed.Size = new System.Drawing.Size(141, 27); - this.numericUpDownSpeed.TabIndex = 3; - this.numericUpDownSpeed.Value = new decimal(new int[] { - 100, - 0, - 0, - 0}); + this.checkBoxSail.AutoSize = true; + this.checkBoxSail.Location = new System.Drawing.Point(6, 168); + this.checkBoxSail.Name = "checkBoxSail"; + this.checkBoxSail.Size = new System.Drawing.Size(169, 24); + this.checkBoxSail.TabIndex = 6; + this.checkBoxSail.Text = "Наличие парусника"; + this.checkBoxSail.UseVisualStyleBackColor = true; + // + // checkBoxHull + // + this.checkBoxHull.AutoSize = true; + this.checkBoxHull.Location = new System.Drawing.Point(6, 127); + this.checkBoxHull.Name = "checkBoxHull"; + this.checkBoxHull.Size = new System.Drawing.Size(237, 24); + this.checkBoxHull.TabIndex = 5; + this.checkBoxHull.Text = "Наличие усиленного корпуса"; + this.checkBoxHull.UseVisualStyleBackColor = true; // // numericUpDownWeight // @@ -221,56 +231,65 @@ 0, 0}); // - // checkBoxHull + // numericUpDownSpeed // - this.checkBoxHull.AutoSize = true; - this.checkBoxHull.Location = new System.Drawing.Point(6, 127); - this.checkBoxHull.Name = "checkBoxHull"; - this.checkBoxHull.Size = new System.Drawing.Size(237, 24); - this.checkBoxHull.TabIndex = 5; - this.checkBoxHull.Text = "Наличие усиленного корпуса"; - this.checkBoxHull.UseVisualStyleBackColor = true; + this.numericUpDownSpeed.Location = new System.Drawing.Point(118, 34); + this.numericUpDownSpeed.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDownSpeed.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(141, 27); + this.numericUpDownSpeed.TabIndex = 3; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); // - // checkBoxSail + // labelWeight // - this.checkBoxSail.AutoSize = true; - this.checkBoxSail.Location = new System.Drawing.Point(6, 168); - this.checkBoxSail.Name = "checkBoxSail"; - this.checkBoxSail.Size = new System.Drawing.Size(169, 24); - this.checkBoxSail.TabIndex = 6; - this.checkBoxSail.Text = "Наличие парусника"; - this.checkBoxSail.UseVisualStyleBackColor = true; + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(25, 79); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(36, 20); + this.labelWeight.TabIndex = 2; + this.labelWeight.Text = "Вес:"; // - // labelSimpleObject + // labelSpeed // - this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelSimpleObject.Location = new System.Drawing.Point(345, 225); - this.labelSimpleObject.Name = "labelSimpleObject"; - this.labelSimpleObject.Size = new System.Drawing.Size(140, 40); - this.labelSimpleObject.TabIndex = 7; - this.labelSimpleObject.Text = "Простой"; - this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(25, 36); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(76, 20); + this.labelSpeed.TabIndex = 1; + this.labelSpeed.Text = "Скорость:"; // - // labelModifiedObject + // panelObject // - this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelModifiedObject.Location = new System.Drawing.Point(489, 225); - this.labelModifiedObject.Name = "labelModifiedObject"; - this.labelModifiedObject.Size = new System.Drawing.Size(140, 40); - this.labelModifiedObject.TabIndex = 8; - this.labelModifiedObject.Text = "Продвинутый"; - this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.panelObject.Controls.Add(this.pictureBoxObject); + this.panelObject.Controls.Add(this.labelAddColor); + this.panelObject.Controls.Add(this.labelColor); + this.panelObject.Location = new System.Drawing.Point(658, 12); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(362, 330); + this.panelObject.TabIndex = 2; + this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); // - // panel1 + // pictureBoxObject // - this.panel1.Controls.Add(this.pictureBoxObject); - this.panel1.Controls.Add(this.labelAddColor); - this.panel1.Controls.Add(this.labelColor); - this.panel1.Location = new System.Drawing.Point(658, 12); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(362, 330); - this.panel1.TabIndex = 2; + this.pictureBoxObject.Location = new System.Drawing.Point(3, 61); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(356, 266); + this.pictureBoxObject.TabIndex = 11; + this.pictureBoxObject.TabStop = false; // // labelAddColor // @@ -292,22 +311,15 @@ this.labelColor.Text = "Цвет"; this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // pictureBoxObject + // buttonOk // - this.pictureBoxObject.Location = new System.Drawing.Point(3, 61); - this.pictureBoxObject.Name = "pictureBoxObject"; - this.pictureBoxObject.Size = new System.Drawing.Size(356, 266); - this.pictureBoxObject.TabIndex = 11; - this.pictureBoxObject.TabStop = false; - // - // buttonAdd - // - this.buttonAdd.Location = new System.Drawing.Point(694, 348); - this.buttonAdd.Name = "buttonAdd"; - this.buttonAdd.Size = new System.Drawing.Size(140, 40); - this.buttonAdd.TabIndex = 3; - this.buttonAdd.Text = "Добавить"; - this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonOk.Location = new System.Drawing.Point(694, 348); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(140, 40); + this.buttonOk.TabIndex = 3; + this.buttonOk.Text = "Добавить"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click); // // buttonCancel // @@ -324,17 +336,17 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1032, 394); this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.buttonAdd); - this.Controls.Add(this.panel1); + this.Controls.Add(this.buttonOk); + this.Controls.Add(this.panelObject); this.Controls.Add(this.groupBoxParameters); this.Name = "FormBoatConfig"; this.Text = "Создание объекта"; this.groupBoxColors.ResumeLayout(false); this.groupBoxParameters.ResumeLayout(false); this.groupBoxParameters.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); - this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + this.panelObject.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); this.ResumeLayout(false); @@ -360,11 +372,11 @@ private NumericUpDown numericUpDownSpeed; private Label labelWeight; private Label labelSpeed; - private Panel panel1; + private Panel panelObject; private PictureBox pictureBoxObject; private Label labelAddColor; private Label labelColor; - private Button buttonAdd; + private Button buttonOk; private Button buttonCancel; } } \ No newline at end of file diff --git a/Sailboat/Sailboat/FormBoatConfig.cs b/Sailboat/Sailboat/FormBoatConfig.cs index ab8a453..3148ca6 100644 --- a/Sailboat/Sailboat/FormBoatConfig.cs +++ b/Sailboat/Sailboat/FormBoatConfig.cs @@ -16,17 +16,8 @@ namespace Sailboat { public partial class FormBoatConfig : Form { - /// - /// Переменная-выбранная машина - /// DrawingBoat? _boat = null; - /// - /// Событие - /// private event BoatDelegate? EventAddBoat; - /// - /// Конструктор - /// public FormBoatConfig() { InitializeComponent(); @@ -41,7 +32,7 @@ namespace Sailboat // TODO buttonCancel.Click with lambda } - private void DrawCar() + private void DrawBoat() { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Graphics gr = Graphics.FromImage(bmp); @@ -49,7 +40,7 @@ namespace Sailboat _boat?.DrawTransport(gr); pictureBoxObject.Image = bmp; } - public void AddEvent(BoatDelegate ev) + internal void AddEvent(BoatDelegate ev) { if (EventAddBoat == null) { @@ -70,11 +61,6 @@ namespace Sailboat (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) @@ -103,7 +89,7 @@ namespace Sailboat pictureBoxObject.Height); break; } - DrawCar(); + DrawBoat(); } private void ButtonOk_Click(object sender, EventArgs e) { -- 2.25.1 From 3677d2733da633487eae1e6c3202a36a092d1f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Wed, 8 Nov 2023 10:38:06 +0400 Subject: [PATCH 4/9] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B4=D0=BE=D0=BB=D0=B6?= =?UTF-8?q?=D0=B0=D1=8E=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/FormBoatConfig.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sailboat/Sailboat/FormBoatConfig.cs b/Sailboat/Sailboat/FormBoatConfig.cs index 3148ca6..b0e2a07 100644 --- a/Sailboat/Sailboat/FormBoatConfig.cs +++ b/Sailboat/Sailboat/FormBoatConfig.cs @@ -29,7 +29,8 @@ namespace Sailboat panelWhite.MouseDown += PanelColor_MouseDown; panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; - // TODO buttonCancel.Click with lambda + + //button_close.Click += (s, e) => Close(); } private void DrawBoat() -- 2.25.1 From 9e26269aa500b006352ce2681d2adc521c6287f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Sat, 18 Nov 2023 13:38:37 +0400 Subject: [PATCH 5/9] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D0=B8=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D1=82=D0=BE=D0=B3=D0=BE=20=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD=D1=83=D1=82=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatDelegate.cs | 11 ------- Sailboat/Sailboat/FormBoatCollection.cs | 29 ++++++++++------- Sailboat/Sailboat/FormBoatConfig.Designer.cs | 33 +++++++++++--------- Sailboat/Sailboat/FormBoatConfig.cs | 6 ++-- 4 files changed, 39 insertions(+), 40 deletions(-) delete mode 100644 Sailboat/Sailboat/BoatDelegate.cs diff --git a/Sailboat/Sailboat/BoatDelegate.cs b/Sailboat/Sailboat/BoatDelegate.cs deleted file mode 100644 index 377892f..0000000 --- a/Sailboat/Sailboat/BoatDelegate.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Sailboat.DrawingObjects; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Sailboat -{ - internal delegate void BoatDelegate(DrawingBoat boat); -} diff --git a/Sailboat/Sailboat/FormBoatCollection.cs b/Sailboat/Sailboat/FormBoatCollection.cs index ea847bb..a86d336 100644 --- a/Sailboat/Sailboat/FormBoatCollection.cs +++ b/Sailboat/Sailboat/FormBoatCollection.cs @@ -49,6 +49,16 @@ namespace Sailboat private void buttonAddBoat_Click(object sender, EventArgs e) { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } + var formBoatConfig = new FormBoatConfig(); formBoatConfig.AddEvent(AddBoat); formBoatConfig.Show(); @@ -66,18 +76,15 @@ namespace Sailboat { return; } - FormSailboat form = new(); - if (form.ShowDialog() == DialogResult.OK) + + if (obj + drawingBoat) { - if (obj + form.SelectedBoat) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowBoats(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowBoats(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } diff --git a/Sailboat/Sailboat/FormBoatConfig.Designer.cs b/Sailboat/Sailboat/FormBoatConfig.Designer.cs index 7a6254c..e991b5f 100644 --- a/Sailboat/Sailboat/FormBoatConfig.Designer.cs +++ b/Sailboat/Sailboat/FormBoatConfig.Designer.cs @@ -46,7 +46,7 @@ this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); this.labelWeight = new System.Windows.Forms.Label(); this.labelSpeed = new System.Windows.Forms.Label(); - this.panelObject = new System.Windows.Forms.Panel(); + this.PanelObject = new System.Windows.Forms.Panel(); this.pictureBoxObject = new System.Windows.Forms.PictureBox(); this.labelAddColor = new System.Windows.Forms.Label(); this.labelColor = new System.Windows.Forms.Label(); @@ -56,7 +56,7 @@ this.groupBoxParameters.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); - this.panelObject.SuspendLayout(); + this.PanelObject.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); this.SuspendLayout(); // @@ -271,17 +271,18 @@ this.labelSpeed.TabIndex = 1; this.labelSpeed.Text = "Скорость:"; // - // panelObject + // PanelObject // - this.panelObject.Controls.Add(this.pictureBoxObject); - this.panelObject.Controls.Add(this.labelAddColor); - this.panelObject.Controls.Add(this.labelColor); - this.panelObject.Location = new System.Drawing.Point(658, 12); - this.panelObject.Name = "panelObject"; - this.panelObject.Size = new System.Drawing.Size(362, 330); - this.panelObject.TabIndex = 2; - this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); - this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); + this.PanelObject.AllowDrop = true; + this.PanelObject.Controls.Add(this.pictureBoxObject); + this.PanelObject.Controls.Add(this.labelAddColor); + this.PanelObject.Controls.Add(this.labelColor); + this.PanelObject.Location = new System.Drawing.Point(658, 12); + this.PanelObject.Name = "PanelObject"; + this.PanelObject.Size = new System.Drawing.Size(362, 330); + this.PanelObject.TabIndex = 2; + this.PanelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.PanelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); // // pictureBoxObject // @@ -293,6 +294,7 @@ // // labelAddColor // + this.labelAddColor.AllowDrop = true; this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelAddColor.Location = new System.Drawing.Point(182, 16); this.labelAddColor.Name = "labelAddColor"; @@ -303,6 +305,7 @@ // // labelColor // + this.labelColor.AllowDrop = true; this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelColor.Location = new System.Drawing.Point(38, 16); this.labelColor.Name = "labelColor"; @@ -337,7 +340,7 @@ this.ClientSize = new System.Drawing.Size(1032, 394); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonOk); - this.Controls.Add(this.panelObject); + this.Controls.Add(this.PanelObject); this.Controls.Add(this.groupBoxParameters); this.Name = "FormBoatConfig"; this.Text = "Создание объекта"; @@ -346,7 +349,7 @@ this.groupBoxParameters.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); - this.panelObject.ResumeLayout(false); + this.PanelObject.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); this.ResumeLayout(false); @@ -372,7 +375,7 @@ private NumericUpDown numericUpDownSpeed; private Label labelWeight; private Label labelSpeed; - private Panel panelObject; + private Panel PanelObject; private PictureBox pictureBoxObject; private Label labelAddColor; private Label labelColor; diff --git a/Sailboat/Sailboat/FormBoatConfig.cs b/Sailboat/Sailboat/FormBoatConfig.cs index b0e2a07..9160d6d 100644 --- a/Sailboat/Sailboat/FormBoatConfig.cs +++ b/Sailboat/Sailboat/FormBoatConfig.cs @@ -17,7 +17,7 @@ namespace Sailboat public partial class FormBoatConfig : Form { DrawingBoat? _boat = null; - private event BoatDelegate? EventAddBoat; + private event Action ? EventAddBoat; public FormBoatConfig() { InitializeComponent(); @@ -30,7 +30,7 @@ namespace Sailboat panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; - //button_close.Click += (s, e) => Close(); + buttonCancel.Click += (s, e) => Close(); } private void DrawBoat() @@ -41,7 +41,7 @@ namespace Sailboat _boat?.DrawTransport(gr); pictureBoxObject.Image = bmp; } - internal void AddEvent(BoatDelegate ev) + internal void AddEvent(Action ev) { if (EventAddBoat == null) { -- 2.25.1 From 03c0f7a6ff05f6a0adc2ec67dd95c7b5ad1580a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Mon, 20 Nov 2023 23:21:11 +0400 Subject: [PATCH 6/9] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= =?UTF-8?q?=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatsGenericCollection.cs | 2 ++ Sailboat/Sailboat/DrawingBoat.cs | 18 ++++++++++-- Sailboat/Sailboat/DrawingSailboat.cs | 5 ++++ Sailboat/Sailboat/EntityBoat.cs | 2 +- Sailboat/Sailboat/EntitySailboat.cs | 2 +- Sailboat/Sailboat/FormBoatConfig.Designer.cs | 4 +++ Sailboat/Sailboat/FormBoatConfig.cs | 30 ++++++++++++++++++++ 7 files changed, 59 insertions(+), 4 deletions(-) diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs index f127575..e5ff477 100644 --- a/Sailboat/Sailboat/BoatsGenericCollection.cs +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -132,6 +132,8 @@ namespace Sailboat.Generics { if (boat != null) { + boat._pictureWidth = _pictureWidth; + boat._pictureHeight = _pictureHeight; int width = _pictureWidth / _placeSizeWidth; boat.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight); boat.DrawTransport(g); diff --git a/Sailboat/Sailboat/DrawingBoat.cs b/Sailboat/Sailboat/DrawingBoat.cs index a0b5c12..26dd29e 100644 --- a/Sailboat/Sailboat/DrawingBoat.cs +++ b/Sailboat/Sailboat/DrawingBoat.cs @@ -12,8 +12,8 @@ namespace Sailboat.DrawingObjects public class DrawingBoat { public EntityBoat? EntityBoat { get; protected set; } - private int _pictureWidth; - private int _pictureHeight; + public int _pictureWidth; + public int _pictureHeight; protected int _startPosX; protected int _startPosY; private readonly int _boatWidth = 160; @@ -143,7 +143,21 @@ namespace Sailboat.DrawingObjects g.FillEllipse(addBrush, _startPosX + 20, _startPosY + 100, 90, 40); g.DrawEllipse(pen, _startPosX + 20, _startPosY + 100, 90, 40); + } + public void SetColor(Color color) + { + if (EntityBoat == null) + { + return; } + EntityBoat.BodyColor = color; + } + + public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight) + { + _pictureWidth = pictureBoxWidth; + _pictureHeight = pictureBoxHeight; } } +} diff --git a/Sailboat/Sailboat/DrawingSailboat.cs b/Sailboat/Sailboat/DrawingSailboat.cs index 130b9cc..4417181 100644 --- a/Sailboat/Sailboat/DrawingSailboat.cs +++ b/Sailboat/Sailboat/DrawingSailboat.cs @@ -64,5 +64,10 @@ namespace Sailboat.DrawingObjects g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 120), new Point(_startPosX + 65, _startPosY)); } } + + public void SetAddColor(Color color) + { + ((EntitySailboat)EntityBoat).AdditionalColor = color; + } } } diff --git a/Sailboat/Sailboat/EntityBoat.cs b/Sailboat/Sailboat/EntityBoat.cs index 6f1da8a..8db9e23 100644 --- a/Sailboat/Sailboat/EntityBoat.cs +++ b/Sailboat/Sailboat/EntityBoat.cs @@ -10,7 +10,7 @@ namespace Sailboat.Entities { public int Speed { get; private set; } public double Weight { get; private set; } - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } public double Step => (double)Speed * 100 / Weight; public EntityBoat(int speed, double weight, Color bodyColor) { diff --git a/Sailboat/Sailboat/EntitySailboat.cs b/Sailboat/Sailboat/EntitySailboat.cs index aff4b68..7f58f36 100644 --- a/Sailboat/Sailboat/EntitySailboat.cs +++ b/Sailboat/Sailboat/EntitySailboat.cs @@ -8,7 +8,7 @@ namespace Sailboat.Entities { public class EntitySailboat : EntityBoat { - public Color AdditionalColor { get; private set; } + public Color AdditionalColor { get; set; } public bool Hull { get; private set; } public bool Sail { get; private set; } public EntitySailboat(int speed, double weight, Color bodyColor, Color diff --git a/Sailboat/Sailboat/FormBoatConfig.Designer.cs b/Sailboat/Sailboat/FormBoatConfig.Designer.cs index e991b5f..d572751 100644 --- a/Sailboat/Sailboat/FormBoatConfig.Designer.cs +++ b/Sailboat/Sailboat/FormBoatConfig.Designer.cs @@ -302,6 +302,8 @@ this.labelAddColor.TabIndex = 10; this.labelAddColor.Text = "Доп. цвет"; this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAddColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); + this.labelAddColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); // // labelColor // @@ -313,6 +315,8 @@ this.labelColor.TabIndex = 9; this.labelColor.Text = "Цвет"; this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); + this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); // // buttonOk // diff --git a/Sailboat/Sailboat/FormBoatConfig.cs b/Sailboat/Sailboat/FormBoatConfig.cs index 9160d6d..7c2ffe9 100644 --- a/Sailboat/Sailboat/FormBoatConfig.cs +++ b/Sailboat/Sailboat/FormBoatConfig.cs @@ -92,6 +92,36 @@ namespace Sailboat } DrawBoat(); } + + private void LabelColor_DragDrop(object sender, DragEventArgs e) + { + if (_boat == null) + return; + switch (((Label)sender).Name) + { + case "labelColor": + _boat.SetColor((Color)e.Data.GetData(typeof(Color))); + break; + case "labelAddColor": + if (!(_boat is DrawingSailboat)) + return; + (_boat as DrawingSailboat).SetAddColor((Color)e.Data.GetData(typeof(Color))); + break; + } + DrawBoat(); + } + private void LabelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(typeof(Color)) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void ButtonOk_Click(object sender, EventArgs e) { EventAddBoat?.Invoke(_boat); -- 2.25.1 From 7451b276285798d3bed133bddfe77da1a0ff8d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Sat, 2 Dec 2023 20:26:36 +0400 Subject: [PATCH 7/9] =?UTF-8?q?=D0=B8=D1=82=D0=BE=D0=B3=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=BB=D0=B0=D0=B1=D1=8B=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/DrawingBoat.cs | 14 -------------- Sailboat/Sailboat/DrawingSailboat.cs | 5 ----- Sailboat/Sailboat/EntityBoat.cs | 3 ++- Sailboat/Sailboat/EntitySailboat.cs | 3 ++- Sailboat/Sailboat/FormBoatConfig.cs | 5 +++-- 5 files changed, 7 insertions(+), 23 deletions(-) diff --git a/Sailboat/Sailboat/DrawingBoat.cs b/Sailboat/Sailboat/DrawingBoat.cs index 26dd29e..daa3898 100644 --- a/Sailboat/Sailboat/DrawingBoat.cs +++ b/Sailboat/Sailboat/DrawingBoat.cs @@ -144,20 +144,6 @@ namespace Sailboat.DrawingObjects g.DrawEllipse(pen, _startPosX + 20, _startPosY + 100, 90, 40); } - public void SetColor(Color color) - { - if (EntityBoat == null) - { - return; - } - EntityBoat.BodyColor = color; - } - - public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight) - { - _pictureWidth = pictureBoxWidth; - _pictureHeight = pictureBoxHeight; - } } } diff --git a/Sailboat/Sailboat/DrawingSailboat.cs b/Sailboat/Sailboat/DrawingSailboat.cs index 4417181..130b9cc 100644 --- a/Sailboat/Sailboat/DrawingSailboat.cs +++ b/Sailboat/Sailboat/DrawingSailboat.cs @@ -64,10 +64,5 @@ namespace Sailboat.DrawingObjects g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 120), new Point(_startPosX + 65, _startPosY)); } } - - public void SetAddColor(Color color) - { - ((EntitySailboat)EntityBoat).AdditionalColor = color; - } } } diff --git a/Sailboat/Sailboat/EntityBoat.cs b/Sailboat/Sailboat/EntityBoat.cs index 8db9e23..7312ee4 100644 --- a/Sailboat/Sailboat/EntityBoat.cs +++ b/Sailboat/Sailboat/EntityBoat.cs @@ -10,7 +10,8 @@ namespace Sailboat.Entities { public int Speed { get; private set; } public double Weight { get; private set; } - public Color BodyColor { get; set; } + public Color BodyColor { get; private set; } + public void setBodyColor(Color color) { BodyColor = color; } public double Step => (double)Speed * 100 / Weight; public EntityBoat(int speed, double weight, Color bodyColor) { diff --git a/Sailboat/Sailboat/EntitySailboat.cs b/Sailboat/Sailboat/EntitySailboat.cs index 7f58f36..af78d9b 100644 --- a/Sailboat/Sailboat/EntitySailboat.cs +++ b/Sailboat/Sailboat/EntitySailboat.cs @@ -8,7 +8,8 @@ namespace Sailboat.Entities { public class EntitySailboat : EntityBoat { - public Color AdditionalColor { get; set; } + public Color AdditionalColor { get; private set; } + public void setAdditionalColor(Color color) { AdditionalColor = color; } public bool Hull { get; private set; } public bool Sail { get; private set; } public EntitySailboat(int speed, double weight, Color bodyColor, Color diff --git a/Sailboat/Sailboat/FormBoatConfig.cs b/Sailboat/Sailboat/FormBoatConfig.cs index 7c2ffe9..a79335f 100644 --- a/Sailboat/Sailboat/FormBoatConfig.cs +++ b/Sailboat/Sailboat/FormBoatConfig.cs @@ -11,6 +11,7 @@ using System.Windows.Forms; using Sailboat.DrawingObjects; using Sailboat.Generics; using Sailboat.MovementStrategy; +using Sailboat.Entities; namespace Sailboat { @@ -100,12 +101,12 @@ namespace Sailboat switch (((Label)sender).Name) { case "labelColor": - _boat.SetColor((Color)e.Data.GetData(typeof(Color))); + _boat.EntityBoat.setBodyColor((Color)e.Data.GetData(typeof(Color))); break; case "labelAddColor": if (!(_boat is DrawingSailboat)) return; - (_boat as DrawingSailboat).SetAddColor((Color)e.Data.GetData(typeof(Color))); + (_boat.EntityBoat as EntitySailboat).setAdditionalColor((Color)e.Data.GetData(typeof(Color))); break; } DrawBoat(); -- 2.25.1 From cdcfa0457246e7315977920805415229aa67c882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Sat, 2 Dec 2023 20:50:13 +0400 Subject: [PATCH 8/9] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8=20=D0=BB=D0=B0=D0=B1=D1=8B=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatsGenericCollection.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs index e5ff477..1aa6f6e 100644 --- a/Sailboat/Sailboat/BoatsGenericCollection.cs +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -132,6 +132,7 @@ namespace Sailboat.Generics { if (boat != null) { + int width = _pictureWidth / _placeSizeWidth; boat._pictureWidth = _pictureWidth; boat._pictureHeight = _pictureHeight; int width = _pictureWidth / _placeSizeWidth; -- 2.25.1 From edc908eb30e87f6e707dfb6b10336e88db699cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Mon, 4 Dec 2023 19:22:39 +0400 Subject: [PATCH 9/9] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatsGenericCollection.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs index 1aa6f6e..7535a70 100644 --- a/Sailboat/Sailboat/BoatsGenericCollection.cs +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -135,7 +135,6 @@ namespace Sailboat.Generics int width = _pictureWidth / _placeSizeWidth; boat._pictureWidth = _pictureWidth; boat._pictureHeight = _pictureHeight; - int width = _pictureWidth / _placeSizeWidth; boat.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight); boat.DrawTransport(g); } -- 2.25.1