5 лаба

This commit is contained in:
Geo7312 2024-04-15 11:03:44 +04:00
parent 950db371a3
commit 0c7bc6aa68
3 changed files with 8 additions and 4 deletions

View File

@ -130,12 +130,14 @@ public class DrawningTrolleyB
/// </summary> /// </summary>
/// <param name="x">Координата X</param> /// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param> /// <param name="y">Координата Y</param>
public void SetPosition(int x, int y) public void SetPosition(int x, int y, int width, int height)
{ {
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
{ {
return; return;
} }
//TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
//то надо изменить координаты, чтобы он оставался в этих границах //то надо изменить координаты, чтобы он оставался в этих границах
if (x + _drawningVehicleWidth > _pictureWidth) if (x + _drawningVehicleWidth > _pictureWidth)
{ {
@ -150,6 +152,7 @@ public class DrawningTrolleyB
} }
else if (y < 0) _startPosY = 0; else if (y < 0) _startPosY = 0;
else _startPosY = y; else _startPosY = y;
} }

View File

@ -50,7 +50,7 @@ public partial class FormTrolleyBCollection : Form
/// Добавление автомобиля в коллекцию /// Добавление автомобиля в коллекцию
/// </summary> /// </summary>
/// <param name="car"></param> /// <param name="car"></param>
private void SetTrolleyB(DrawningTrolleyB? trolleyB) private void SetTrolleyB(DrawningTrolleyB trolleyB)
{ {
if (_company == null || trolleyB == null) if (_company == null || trolleyB == null)
{ {

View File

@ -24,6 +24,7 @@ public partial class FormTrolleyBConfig : Form
/// </summary> /// </summary>
public FormTrolleyBConfig() public FormTrolleyBConfig()
{ {
InitializeComponent();
panelRed.MouseDown += Panel_MouseDown; panelRed.MouseDown += Panel_MouseDown;
panelGreen.MouseDown += Panel_MouseDown; panelGreen.MouseDown += Panel_MouseDown;
panelBlue.MouseDown += Panel_MouseDown; panelBlue.MouseDown += Panel_MouseDown;
@ -35,7 +36,7 @@ public partial class FormTrolleyBConfig : Form
buttonCancel.Click += (s, e) => Close(); buttonCancel.Click += (s, e) => Close();
InitializeComponent();
} }
/// <summary> /// <summary>
@ -55,7 +56,7 @@ public partial class FormTrolleyBConfig : Form
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_trolleyB?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height); _trolleyB?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
_trolleyB?.SetPosition(5, 5); _trolleyB?.SetPosition(5, 5, Width, Height);
_trolleyB?.DrawTransport(gr); _trolleyB?.DrawTransport(gr);
pictureBoxObject.Image = bmp; pictureBoxObject.Image = bmp;
} }