From f0beec428c6f830b624a31016ae346a1d6b2cb1e Mon Sep 17 00:00:00 2001 From: tellsense Date: Mon, 25 Dec 2023 20:08:47 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D1=81=D1=82=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=201=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormElectricLocomotive.Designer.cs | 107 +++++++++++++++++- .../FormElectricLocomotive.cs | 54 +++++++++ 2 files changed, 157 insertions(+), 4 deletions(-) diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs index 223ed84..97b60c5 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs @@ -28,12 +28,111 @@ /// private void InitializeComponent() { - components = new System.ComponentModel.Container(); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Text = "Form1"; + pictureBoxElectricLocomotive = new PictureBox(); + buttonCreate = new Button(); + buttonLeft = new Button(); + buttonRight = new Button(); + buttonUp = new Button(); + buttonDown = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit(); + SuspendLayout(); + // + // pictureBoxElectricLocomotive + // + pictureBoxElectricLocomotive.Cursor = Cursors.No; + pictureBoxElectricLocomotive.Dock = DockStyle.Fill; + pictureBoxElectricLocomotive.Enabled = false; + pictureBoxElectricLocomotive.Location = new Point(0, 0); + pictureBoxElectricLocomotive.Name = "pictureBoxElectricLocomotive"; + pictureBoxElectricLocomotive.Size = new Size(1052, 553); + pictureBoxElectricLocomotive.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxElectricLocomotive.TabIndex = 0; + pictureBoxElectricLocomotive.TabStop = false; + pictureBoxElectricLocomotive.Click += buttonMove_Click; + // + // buttonCreate + // + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(0, 490); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(172, 63); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.free_icon_left_arrow_line_symbol_54321; + buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; + buttonLeft.Location = new Point(938, 511); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(30, 30); + buttonLeft.TabIndex = 2; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += buttonMove_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.free_icon_right_arrow_angle_54833; + buttonRight.BackgroundImageLayout = ImageLayout.Zoom; + buttonRight.Location = new Point(1010, 511); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(30, 30); + buttonRight.TabIndex = 3; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += buttonMove_Click; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.free_icon_up_arrow_angle_54817; + buttonUp.BackgroundImageLayout = ImageLayout.Zoom; + buttonUp.Location = new Point(974, 475); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(30, 30); + buttonUp.TabIndex = 4; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += buttonMove_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.free_icon_down_arrow_54785; + buttonDown.BackgroundImageLayout = ImageLayout.Zoom; + buttonDown.Location = new Point(974, 511); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(30, 30); + buttonDown.TabIndex = 5; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += buttonMove_Click; + // + // FormElectricLocomotive + // + ClientSize = new Size(1052, 553); + Controls.Add(buttonDown); + Controls.Add(buttonUp); + Controls.Add(buttonRight); + Controls.Add(buttonLeft); + Controls.Add(buttonCreate); + Controls.Add(pictureBoxElectricLocomotive); + Name = "FormElectricLocomotive"; + StartPosition = FormStartPosition.CenterScreen; + Text = "ElectricLocomotive"; + ((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion + + private PictureBox pictureBoxElectricLocomotive; + private Button buttonCreate; + private Button buttonLeft; + private Button buttonRight; + private Button buttonUp; + private Button buttonDown; } } \ No newline at end of file diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs index 168dce9..f165c47 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs @@ -2,9 +2,63 @@ namespace ProjectElectricLocomotive { public partial class FormElectricLocomotive : Form { + private DrawningElectricLocomotive? _drawningElectricLocomotive; public FormElectricLocomotive() { InitializeComponent(); } + private void Draw() + { + if (_drawningElectricLocomotive == null) + { + return; + } + Bitmap bmp = new(pictureBoxElectricLocomotive.Width, + pictureBoxElectricLocomotive.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningElectricLocomotive.DrawTransport(gr); + pictureBoxElectricLocomotive.Image = bmp; + } + /// + /// + private void buttonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningElectricLocomotive = new DrawningElectricLocomotive(); + _drawningElectricLocomotive.Init(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2)), + pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height); + _drawningElectricLocomotive.SetPosition(random.Next(1, 100), random.Next(1, 100)); + Draw(); + } + /// + /// + private void buttonMove_Click(object sender, EventArgs e) + { + if (_drawningElectricLocomotive == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawningElectricLocomotive.MoveTransport(Direction.Up); + break; + case "buttonDown": + _drawningElectricLocomotive.MoveTransport(Direction.Down); + break; + case "buttonLeft": + _drawningElectricLocomotive.MoveTransport(Direction.Left); + break; + case "buttonRight": + _drawningElectricLocomotive.MoveTransport(Direction.Right); + break; + } + Draw(); + } } } \ No newline at end of file