Первая лабораторная работа. Готовая

This commit is contained in:
Ксения Клюшенкова 2023-01-27 20:45:39 +04:00
parent fac144598a
commit ba1cfd6bc6
2 changed files with 29 additions and 22 deletions

View File

@ -105,7 +105,7 @@
this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 3; this.buttonRight.TabIndex = 3;
this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonRight_Click); this.buttonRight.Click += new System.EventHandler(this.ButtonMove_click);
// //
// buttonLeft // buttonLeft
// //
@ -117,7 +117,7 @@
this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4; this.buttonLeft.TabIndex = 4;
this.buttonLeft.UseVisualStyleBackColor = true; this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.buttonLeft_Click); this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_click);
// //
// buttonDown // buttonDown
// //
@ -129,7 +129,7 @@
this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 5; this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonDown_Click); this.buttonDown.Click += new System.EventHandler(this.ButtonMove_click);
// //
// buttonUp // buttonUp
// //
@ -141,7 +141,7 @@
this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 6; this.buttonUp.TabIndex = 6;
this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonUp_Click); this.buttonUp.Click += new System.EventHandler(this.ButtonMove_click);
// //
// FormLokomotive // FormLokomotive
// //
@ -167,6 +167,14 @@
#endregion #endregion
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private StatusStrip statusStrip1; private StatusStrip statusStrip1;
private ToolStripStatusLabel toolStripStatusLabelSpeed; private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight; private ToolStripStatusLabel toolStripStatusLabelWeight;

View File

@ -40,25 +40,24 @@ namespace Warmly_Lokomotive_Base
private void pictureBox1_Click(object sender, EventArgs e) private void pictureBox1_Click(object sender, EventArgs e)
{ {
} }
private void buttonRight_Click(object sender, EventArgs e) private void ButtonMove_click(object sender, EventArgs e)
{ {
_locomotive?.MoveTransport(Direction.Right); string name = ((Button)sender)?.Name ?? string.Empty;
Draw(); switch (name)
}
private void buttonLeft_Click(object sender, EventArgs e)
{
_locomotive?.MoveTransport(Direction.Left);
Draw();
}
private void buttonDown_Click(object sender, EventArgs e)
{
_locomotive?.MoveTransport(Direction.Down);
Draw();
}
private void buttonUp_Click(object sender, EventArgs e)
{ {
case "buttonUp":
_locomotive?.MoveTransport(Direction.Up); _locomotive?.MoveTransport(Direction.Up);
break;
case "buttonDown":
_locomotive?.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_locomotive?.MoveTransport(Direction.Left);
break;
case "buttonRight":
_locomotive?.MoveTransport(Direction.Right);
break;
}
Draw(); Draw();
} }