namespace HoistingCrane { public partial class FormHoistingCrane : Form { private DrawingHoistingCrane _hoistingCrane; 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 ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); _hoistingCrane = new DrawingHoistingCrane(); _hoistingCrane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _hoistingCrane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height); toolStripStatusLabelSpeed.Text = $"Скорость: {_hoistingCrane.HoistingCrane.Speed}"; toolStripStatusLabelWeight.Text = $"Вес: {_hoistingCrane.HoistingCrane.Weight}"; toolStripStatusLabelBodyColor.Text = $"Цвет: {_hoistingCrane.HoistingCrane.BodyColor.Name} "; 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 PictureBoxBulldozer_Resize(object sender, EventArgs e) { _hoistingCrane?.ChangeBorders(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height); Draw(); } } }