PIbd-22-Romanov-E.V.-Hoisti.../HoistingCrane/HoistingCrane/FormHoistingCrane.cs
2022-12-25 11:23:01 +04:00

104 lines
3.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}
}