diff --git a/Lab1ContainersShip/Lab1ContainersShip/DrawingContainerShip.cs b/Lab1ContainersShip/Lab1ContainersShip/DrawingContainerShip.cs index bbfee78..b6d1ec3 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/DrawingContainerShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/DrawingContainerShip.cs @@ -60,5 +60,13 @@ additionalColor, bool crane, bool containers, int width, int height) : g.DrawLine(pen, _startPosX + 47, _startPosY + 13, _startPosX + 47, _startPosY + 25); } } + public void setAddColor(Color color) + { + if (EntityShip is EntityContainerShip ) + { + (EntityShip as EntityContainerShip).setAddColor(color); + } + + } } } diff --git a/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs b/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs index af7b2b5..36f0ab4 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs @@ -16,11 +16,11 @@ namespace Lab1ContainersShip.DrawingObjects /// /// Ширина окна /// - private int _pictureWidth; + public int _pictureWidth; /// /// Высота окна /// - private int _pictureHeight; + public int _pictureHeight; /// /// Левая координата прорисовки автомобиля /// @@ -182,5 +182,9 @@ namespace Lab1ContainersShip.DrawingObjects //контейнеры } + public void setColor(Color color) + { + EntityShip.setColor(color); + } } } diff --git a/Lab1ContainersShip/Lab1ContainersShip/EntityContainerShip.cs b/Lab1ContainersShip/Lab1ContainersShip/EntityContainerShip.cs index 3d9dde6..ac0b7a1 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/EntityContainerShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/EntityContainerShip.cs @@ -25,5 +25,9 @@ namespace Lab1ContainersShip.Entities Crane = crane; Conteiners = containers; } + public void setAddColor(Color color) + { + AdditionalColor = color; + } } } diff --git a/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs b/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs index 001df77..7b052f3 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs @@ -30,5 +30,9 @@ namespace Lab1ContainersShip.Entities BodyColor = bodyColor; } + public void setColor(Color color) + { + BodyColor = color; + } } } diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs index cd21bce..30f6a40 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs @@ -68,27 +68,39 @@ namespace Lab1ContainersShip { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; } - FormContainerShip form = new FormContainerShip(); - if (form.ShowDialog() == DialogResult.OK) + FormShipConfig formShipConfig = new FormShipConfig(); + formShipConfig.AddEvent(addShip); + formShipConfig.Show(); + + + } + private void addShip(DrawingShip drawningShip) + { + if (listBoxStorages.SelectedIndex == -1) { - if ((obj + form.SelectedShip) != 1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowShips(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + return; } - - + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } + + if ((obj + drawningShip) != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowShips(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } private void ButtonRemoveCar_Click(object sender, EventArgs e) diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.Designer.cs b/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.Designer.cs new file mode 100644 index 0000000..d933236 --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.Designer.cs @@ -0,0 +1,426 @@ +namespace Lab1ContainersShip +{ + partial class FormShipConfig + { + /// + /// 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.groupBox1 = new System.Windows.Forms.GroupBox(); + this.labelModifiedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.panelPink = new System.Windows.Forms.Panel(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelLightBlue = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panel6 = new System.Windows.Forms.Panel(); + this.panelOrange = new System.Windows.Forms.Panel(); + this.panel4 = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.panel2 = new System.Windows.Forms.Panel(); + this.checkBoxContainers = new System.Windows.Forms.CheckBox(); + this.checkBoxCrane = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.panel12 = new System.Windows.Forms.Panel(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.buttonOk = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelColor = new System.Windows.Forms.Label(); + this.labelAddColor = new System.Windows.Forms.Label(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.panelYellow.SuspendLayout(); + this.panelOrange.SuspendLayout(); + this.panelRed.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + this.panel12.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.labelModifiedObject); + this.groupBox1.Controls.Add(this.labelSimpleObject); + this.groupBox1.Controls.Add(this.groupBox2); + this.groupBox1.Controls.Add(this.checkBoxContainers); + this.groupBox1.Controls.Add(this.checkBoxCrane); + this.groupBox1.Controls.Add(this.numericUpDownWeight); + this.groupBox1.Controls.Add(this.numericUpDownSpeed); + this.groupBox1.Controls.Add(this.label3); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Location = new System.Drawing.Point(12, 12); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(466, 323); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Параметры"; + // + // labelModifiedObject + // + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(331, 229); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(100, 32); + this.labelModifiedObject.TabIndex = 10; + this.labelModifiedObject.Text = "Продвинутый"; + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(206, 229); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(100, 32); + this.labelSimpleObject.TabIndex = 9; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.panelPink); + this.groupBox2.Controls.Add(this.panelPurple); + this.groupBox2.Controls.Add(this.panelBlue); + this.groupBox2.Controls.Add(this.panelLightBlue); + this.groupBox2.Controls.Add(this.panelGreen); + this.groupBox2.Controls.Add(this.panelYellow); + this.groupBox2.Controls.Add(this.panelOrange); + this.groupBox2.Controls.Add(this.panelRed); + this.groupBox2.Location = new System.Drawing.Point(196, 31); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(246, 158); + this.groupBox2.TabIndex = 8; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Цвета"; + // + // panelPink + // + this.panelPink.BackColor = System.Drawing.Color.Fuchsia; + this.panelPink.Location = new System.Drawing.Point(187, 75); + this.panelPink.Name = "panelPink"; + this.panelPink.Size = new System.Drawing.Size(43, 41); + this.panelPink.TabIndex = 0; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(64))))); + this.panelPurple.Location = new System.Drawing.Point(125, 75); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(43, 40); + this.panelPurple.TabIndex = 0; + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(64, 75); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(43, 40); + this.panelBlue.TabIndex = 0; + // + // panelLightBlue + // + this.panelLightBlue.BackColor = System.Drawing.Color.Cyan; + this.panelLightBlue.Location = new System.Drawing.Point(6, 75); + this.panelLightBlue.Name = "panelLightBlue"; + this.panelLightBlue.Size = new System.Drawing.Size(40, 40); + this.panelLightBlue.TabIndex = 13; + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.Lime; + this.panelGreen.Location = new System.Drawing.Point(187, 19); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(43, 41); + this.panelGreen.TabIndex = 12; + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Controls.Add(this.panel6); + this.panelYellow.Location = new System.Drawing.Point(125, 19); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(43, 38); + this.panelYellow.TabIndex = 11; + // + // panel6 + // + this.panel6.Location = new System.Drawing.Point(0, 44); + this.panel6.Name = "panel6"; + this.panel6.Size = new System.Drawing.Size(43, 56); + this.panel6.TabIndex = 0; + // + // panelOrange + // + this.panelOrange.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0))))); + this.panelOrange.Controls.Add(this.panel4); + this.panelOrange.Location = new System.Drawing.Point(64, 19); + this.panelOrange.Name = "panelOrange"; + this.panelOrange.Size = new System.Drawing.Size(43, 38); + this.panelOrange.TabIndex = 10; + // + // panel4 + // + this.panel4.Location = new System.Drawing.Point(0, 44); + this.panel4.Name = "panel4"; + this.panel4.Size = new System.Drawing.Size(43, 56); + this.panel4.TabIndex = 0; + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Controls.Add(this.panel2); + this.panelRed.Location = new System.Drawing.Point(6, 19); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(40, 38); + this.panelRed.TabIndex = 9; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panel2 + // + this.panel2.Location = new System.Drawing.Point(157, 72); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(43, 28); + this.panel2.TabIndex = 0; + // + // checkBoxContainers + // + this.checkBoxContainers.AutoSize = true; + this.checkBoxContainers.Location = new System.Drawing.Point(9, 129); + this.checkBoxContainers.Name = "checkBoxContainers"; + this.checkBoxContainers.Size = new System.Drawing.Size(88, 17); + this.checkBoxContainers.TabIndex = 7; + this.checkBoxContainers.Text = "Контейнеры"; + this.checkBoxContainers.UseVisualStyleBackColor = true; + // + // checkBoxCrane + // + this.checkBoxCrane.AutoSize = true; + this.checkBoxCrane.Location = new System.Drawing.Point(9, 106); + this.checkBoxCrane.Name = "checkBoxCrane"; + this.checkBoxCrane.Size = new System.Drawing.Size(51, 17); + this.checkBoxCrane.TabIndex = 6; + this.checkBoxCrane.Text = "Кран"; + this.checkBoxCrane.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(41, 65); + 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(120, 20); + this.numericUpDownWeight.TabIndex = 5; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(70, 29); + 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(120, 20); + this.numericUpDownSpeed.TabIndex = 4; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(17, 47); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(0, 13); + this.label3.TabIndex = 3; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(6, 67); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(29, 13); + this.label2.TabIndex = 2; + this.label2.Text = "Вес:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 31); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(58, 13); + this.label1.TabIndex = 1; + this.label1.Text = "Скорость:"; + // + // panel12 + // + this.panel12.AllowDrop = true; + this.panel12.Controls.Add(this.pictureBoxObject); + this.panel12.Location = new System.Drawing.Point(484, 43); + this.panel12.Name = "panel12"; + this.panel12.Size = new System.Drawing.Size(316, 235); + this.panel12.TabIndex = 1; + this.panel12.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.panel12.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(3, 3); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(310, 204); + this.pictureBoxObject.TabIndex = 0; + this.pictureBoxObject.TabStop = false; + // + // buttonOk + // + this.buttonOk.Location = new System.Drawing.Point(526, 284); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(89, 39); + this.buttonOk.TabIndex = 2; + this.buttonOk.Text = "Добавить"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(702, 284); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(95, 39); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // labelColor + // + this.labelColor.AllowDrop = true; + this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelColor.Location = new System.Drawing.Point(494, 12); + this.labelColor.Name = "labelColor"; + this.labelColor.Size = new System.Drawing.Size(100, 23); + this.labelColor.TabIndex = 4; + this.labelColor.Text = "Цвет"; + this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); + this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); + // + // labelAddColor + // + this.labelAddColor.AllowDrop = true; + this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAddColor.Location = new System.Drawing.Point(632, 13); + this.labelAddColor.Name = "labelAddColor"; + this.labelAddColor.Size = new System.Drawing.Size(100, 23); + this.labelAddColor.TabIndex = 5; + this.labelAddColor.Text = "Доп. цвет"; + this.labelAddColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAddColor_DragDrop); + this.labelAddColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); + // + // FormShipConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 347); + this.Controls.Add(this.labelAddColor); + this.Controls.Add(this.labelColor); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOk); + this.Controls.Add(this.panel12); + this.Controls.Add(this.groupBox1); + this.Name = "FormShipConfig"; + this.Text = "FormShipConfig"; + this.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAddColor_DragDrop); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.panelYellow.ResumeLayout(false); + this.panelOrange.ResumeLayout(false); + this.panelRed.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + this.panel12.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.CheckBox checkBoxContainers; + private System.Windows.Forms.CheckBox checkBoxCrane; + private System.Windows.Forms.NumericUpDown numericUpDownWeight; + private System.Windows.Forms.NumericUpDown numericUpDownSpeed; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label labelSimpleObject; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Panel panelPink; + private System.Windows.Forms.Panel panelPurple; + private System.Windows.Forms.Panel panelBlue; + private System.Windows.Forms.Panel panelLightBlue; + private System.Windows.Forms.Panel panelGreen; + private System.Windows.Forms.Panel panelYellow; + private System.Windows.Forms.Panel panel6; + private System.Windows.Forms.Panel panelOrange; + private System.Windows.Forms.Panel panel4; + private System.Windows.Forms.Panel panelRed; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Label labelModifiedObject; + private System.Windows.Forms.Panel panel12; + private System.Windows.Forms.PictureBox pictureBoxObject; + private System.Windows.Forms.Button buttonOk; + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.Label labelColor; + private System.Windows.Forms.Label labelAddColor; + } +} \ No newline at end of file diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.cs b/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.cs new file mode 100644 index 0000000..2ffcf2b --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.cs @@ -0,0 +1,134 @@ +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 Lab1ContainersShip.DrawingObjects; +using Lab1ContainersShip.Entities; + + +namespace Lab1ContainersShip +{ + public partial class FormShipConfig : Form + { + DrawingShip _ship = null; + /// + /// Событие + /// + + private event ShipDelegate EventAddShip; + public void AddEvent(ShipDelegate ev) + { + if (EventAddShip == null) + { + EventAddShip = ev; + } + else + { + EventAddShip += ev; + } + } + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddShip?.Invoke(_ship); + Close(); + } + + public FormShipConfig() + { + InitializeComponent(); + panelRed.MouseDown += PanelColor_MouseDown; + panelOrange.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelLightBlue.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelPink.MouseDown += PanelColor_MouseDown; + buttonCancel.Click += (s, e) => Close(); + } + private void DrawShip() + { + Bitmap bmp = new Bitmap(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _ship?.SetPosition(5, 5); + _ship?.DrawShip(gr); + pictureBoxObject.Image = bmp; + } + + + 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": + _ship = new DrawingShip((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _ship = new DrawingContainerShip((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxCrane.Checked, + checkBoxContainers.Checked, pictureBoxObject.Width,pictureBoxObject.Height); + break; + } + DrawShip(); + } + + + 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))) + e.Effect = DragDropEffects.Copy; + else + { + e.Effect = DragDropEffects.None; + } + } + + private void LabelColor_DragDrop(object sender, DragEventArgs e) + { + + if (_ship is DrawingShip) + { + labelColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + _ship.setColor((Color)e.Data.GetData(typeof(Color))); + } + DrawShip(); + } + + private void LabelAddColor_DragDrop(object sender, DragEventArgs e) + { + + if (_ship is DrawingContainerShip) + { + labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + (_ship as DrawingContainerShip).setAddColor((Color)e.Data.GetData(typeof(Color))); + } + DrawShip(); + } + } +} diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.resx b/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/FormShipConfig.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/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj b/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj index f83dbfb..391051f 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj +++ b/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj @@ -53,6 +53,12 @@ FormShipCollection.cs + + Form + + + FormShipConfig.cs + @@ -74,6 +80,7 @@ + FormContainerShip.cs @@ -81,6 +88,9 @@ FormShipCollection.cs + + FormShipConfig.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/Lab1ContainersShip/Lab1ContainersShip/ShipDelegate.cs b/Lab1ContainersShip/Lab1ContainersShip/ShipDelegate.cs new file mode 100644 index 0000000..1996e93 --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/ShipDelegate.cs @@ -0,0 +1,12 @@ +using Lab1ContainersShip.DrawingObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lab1ContainersShip +{ + public delegate void ShipDelegate(DrawingShip ship); + +} diff --git a/Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs b/Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs index 6fd49c7..67a369e 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs @@ -131,6 +131,8 @@ namespace Lab1ContainersShip if (ship != null) { + ship._pictureHeight = _pictureHeight; + ship._pictureWidth = _pictureWidth; ship.SetPosition(((_collection._maxCount -i - 1) % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (_collection._maxCount - i-1) / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight); ship.DrawShip(g); }