From da78cd7c698d3dac8adc89fa96da371069379740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?10=D0=93=20=D0=95=D0=B3=D0=BE=D1=80=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Mon, 10 Oct 2022 19:53:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A2=D1=80=D0=B5=D1=82=D1=8C=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormHoistingCrane.Designer.cs | 207 ++++++++++++++++++ .../HoistingCrane/FormHoistingCrane.cs | 104 +++++++++ 2 files changed, 311 insertions(+) create mode 100644 HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs create mode 100644 HoistingCrane/HoistingCrane/FormHoistingCrane.cs diff --git a/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs b/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs new file mode 100644 index 0000000..6418a51 --- /dev/null +++ b/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs @@ -0,0 +1,207 @@ +namespace HoistingCrane +{ + partial class FormHoistingCrane + { + /// + /// 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.buttonUp = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.statusStrip = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.pictureBoxHoistingCrane = new System.Windows.Forms.PictureBox(); + this.buttonCreateModify = new System.Windows.Forms.Button(); + this.buttonSelect = new System.Windows.Forms.Button(); + this.statusStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxHoistingCrane)).BeginInit(); + this.SuspendLayout(); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::HoistingCrane.Properties.Resources.up; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonUp.Location = new System.Drawing.Point(722, 353); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 0; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::HoistingCrane.Properties.Resources.left; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonLeft.Location = new System.Drawing.Point(686, 389); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 1; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::HoistingCrane.Properties.Resources.right; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonRight.Location = new System.Drawing.Point(758, 389); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 2; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::HoistingCrane.Properties.Resources.down; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonDown.Location = new System.Drawing.Point(722, 389); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 3; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonCreate + // + this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreate.Location = new System.Drawing.Point(12, 393); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.TabIndex = 4; + this.buttonCreate.Text = "Создать"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); + // + // statusStrip + // + this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelBodyColor}); + this.statusStrip.Location = new System.Drawing.Point(0, 428); + this.statusStrip.Name = "statusStrip"; + this.statusStrip.Size = new System.Drawing.Size(800, 22); + this.statusStrip.TabIndex = 5; + this.statusStrip.Text = "statusStrip"; + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17); + this.toolStripStatusLabelSpeed.Text = "Скорость:"; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17); + this.toolStripStatusLabelWeight.Text = "Вес:"; + // + // toolStripStatusLabelBodyColor + // + this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); + this.toolStripStatusLabelBodyColor.Text = "Цвет:"; + // + // pictureBoxHoistingCrane + // + this.pictureBoxHoistingCrane.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxHoistingCrane.Location = new System.Drawing.Point(0, 0); + this.pictureBoxHoistingCrane.Name = "pictureBoxHoistingCrane"; + this.pictureBoxHoistingCrane.Size = new System.Drawing.Size(800, 428); + this.pictureBoxHoistingCrane.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxHoistingCrane.TabIndex = 6; + this.pictureBoxHoistingCrane.TabStop = false; + this.pictureBoxHoistingCrane.Click += new System.EventHandler(this.pictureBoxHoistingCrane_Click); + this.pictureBoxHoistingCrane.Resize += new System.EventHandler(this.PictureBoxHoistingCrane_Resize); + // + // buttonCreateModify + // + this.buttonCreateModify.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreateModify.Location = new System.Drawing.Point(93, 393); + this.buttonCreateModify.Name = "buttonCreateModify"; + this.buttonCreateModify.Size = new System.Drawing.Size(100, 23); + this.buttonCreateModify.TabIndex = 7; + this.buttonCreateModify.Text = "Модификация"; + + this.buttonSelect.Location = new System.Drawing.Point(551, 390); + this.buttonSelect.Name = "buttonSelect"; + this.buttonSelect.Size = new System.Drawing.Size(75, 23); + this.buttonSelect.TabIndex = 8; + this.buttonSelect.Text = "Выбрать"; + this.buttonSelect.UseVisualStyleBackColor = true; + this.buttonSelect.Click += new System.EventHandler(this.ButtonSelect_Click); + // + this.buttonCreateModify.UseVisualStyleBackColor = true; + this.buttonCreateModify.Click += new System.EventHandler(this.ButtonCreateModify_Click); + // + // FormHoistingCrane + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSelect); + this.Controls.Add(this.buttonCreateModify); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.pictureBoxHoistingCrane); + this.Controls.Add(this.statusStrip); + this.Name = "FormHoistingCrane"; + this.Text = "Подъёмный кран"; + this.statusStrip.ResumeLayout(false); + this.statusStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxHoistingCrane)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonUp; + private Button buttonLeft; + private Button buttonRight; + private Button buttonDown; + private Button buttonCreate; + private StatusStrip statusStrip; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelBodyColor; + private PictureBox pictureBoxHoistingCrane; + private Button buttonCreateModify; + private Button buttonSelect; + } +} \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/FormHoistingCrane.cs b/HoistingCrane/HoistingCrane/FormHoistingCrane.cs new file mode 100644 index 0000000..a31b615 --- /dev/null +++ b/HoistingCrane/HoistingCrane/FormHoistingCrane.cs @@ -0,0 +1,104 @@ +namespace HoistingCrane +{ + public partial class FormHoistingCrane : Form + { + private DrawingHoistingCrane _HoistingCrane; + public DrawingHoistingCrane SelectedHoistingCrane { get; private set; } + public FormHoistingCrane() + { + InitializeComponent(); + } + + private void Draw() + { + Bitmap bmp = new(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height); + Graphics gr = Graphics.FromImage(bmp); + _HoistingCrane?.DrawTransport(gr); + pictureBoxHoistingCrane.Image = bmp; + } + + private void SetData() + { + Random rnd = new(); + _HoistingCrane.SetPosition(rnd.Next(80, 100), rnd.Next(80, 100), pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height); + toolStripStatusLabelSpeed.Text = $"Скорость: {_HoistingCrane.HoistingCrane.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {_HoistingCrane.HoistingCrane.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет:{_HoistingCrane.HoistingCrane.BodyColor.Name}"; + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), + rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _HoistingCrane = new DrawingHoistingCrane(rnd.Next(30, 100), rnd.Next(300, 500), color); + SetData(); + Draw(); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _HoistingCrane?.MoveTransport(Direction.Up); + break; + case "buttonDown": + _HoistingCrane?.MoveTransport(Direction.Down); + break; + case "buttonLeft": + _HoistingCrane?.MoveTransport(Direction.Left); + break; + case "buttonRight": + _HoistingCrane?.MoveTransport(Direction.Right); + break; + } + Draw(); + } + + private void PictureBoxHoistingCrane_Resize(object sender, EventArgs e) + { + _HoistingCrane?.ChangeBorders(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height); + Draw(); + } + + private void ButtonCreateModify_Click(object sender, EventArgs e) + { + Random rnd = new(); + Color selectedColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), + rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + selectedColor = dialog.Color; + } + Color advancedSelectedColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), + rnd.Next(0, 256)); + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + advancedSelectedColor = dialogDop.Color; + } + _HoistingCrane = new DrawingAdvancedHoistingCrane(rnd.Next(30, 100), rnd.Next(300, 500), + selectedColor, advancedSelectedColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); + SetData(); + Draw(); + } + + private void pictureBoxHoistingCrane_Click(object sender, EventArgs e) + { + + } + private void ButtonSelect_Click(object sender, EventArgs e) + { + SelectedHoistingCrane = _HoistingCrane; + DialogResult = DialogResult.OK; + } + } +} \ No newline at end of file