namespace Liner { public partial class MainScreen : Form { /// /// Поле-объект для прорисовки объекта /// private DrawingLiner? _drawingLiner; private Bitmap bmp; /// /// Инициализация формы /// public MainScreen() { InitializeComponent(); bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height); } /// /// Метод прорисовки лайнера /// private void Draw() { if (_drawingLiner == null) { return; } Graphics gr = Graphics.FromImage(bmp); gr.Clear(Color.White); _drawingLiner.DrawTransport(gr); pictureBoxLiner.Image = bmp; gr.Dispose(); } private void buttonCreate_Click(object sender, EventArgs e) { Random random = new(); _drawingLiner = new DrawingLiner(); _drawingLiner.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)), pictureBoxLiner.Width, pictureBoxLiner.Height); _drawingLiner.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void buttonMove_Click(object sender, EventArgs e) { if (_drawingLiner == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; switch (name) { case "buttonUp": _drawingLiner.MoveTransport(DirectionType.Up); break; case "buttonDown": _drawingLiner.MoveTransport(DirectionType.Down); break; case "buttonLeft": _drawingLiner.MoveTransport(DirectionType.Left); break; case "buttonRight": _drawingLiner.MoveTransport(DirectionType.Right); break; } Draw(); } } }