diff --git a/Lab1/DrawingElectroTrans.cs b/Lab1/DrawingElectroTrans.cs
index 2d6b998..65ff3ed 100644
--- a/Lab1/DrawingElectroTrans.cs
+++ b/Lab1/DrawingElectroTrans.cs
@@ -49,6 +49,7 @@ public class DrawingElectroTrans
/// Признак активности усов
/// Признак колличества колес
/// Признак наличия бптпрей
+
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool horns, int wheels, bool battery)
{
@@ -59,7 +60,6 @@ public class DrawingElectroTrans
_startPosX = null;
_startPosY = null;
}
-
///
/// Установка границ поля
///
@@ -68,6 +68,12 @@ public class DrawingElectroTrans
/// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах
public bool SetPictureSize(int width, int height)
{
+ if (width < 100 || height < 100)
+ {
+ _pictureWidth = Config.screenSize.Width;
+ _pictureHeight = Config.screenSize.Height;
+ return false;
+ }
_pictureWidth = width;
_pictureHeight = height;
return true;
@@ -88,18 +94,18 @@ public class DrawingElectroTrans
if (x < 40)
{
x = 40;
- }else if (x > Config.screenSize.Width - 40)
+ }else if (x > _pictureWidth - 40)
{
- x = Config.screenSize.Width - 40;
+ x = _pictureWidth.Value - 40;
}
if (y < 40)
{
y = 40;
}
- else if (y > Config.screenSize.Height - 40)
+ else if (y > _pictureHeight - 40)
{
- y = Config.screenSize.Height - 40;
+ y = _pictureHeight.Value - 40;
}
_startPosX = x;
@@ -118,7 +124,7 @@ public class DrawingElectroTrans
{
return false;
}
- if (_startPosX.Value < 40 || _startPosY.Value < 40 || _startPosX > Config.screenSize.Width - 40 || _startPosY > Config.screenSize.Height - 40)
+ if (_startPosX.Value < 40 || _startPosY.Value < 40 || _startPosX > _pictureWidth - 40 || _startPosY > _pictureHeight - 40)
{
return false;
}
@@ -142,14 +148,14 @@ public class DrawingElectroTrans
return true;
// вправо
case DirectionType.Right:
- if (_startPosX.Value + EntityElectroTrans.Step < Config.screenSize.Width - 40)
+ if (_startPosX.Value + EntityElectroTrans.Step < _pictureWidth - 40)
{
_startPosX += (int)EntityElectroTrans.Step;
}
return true;
//вниз
case DirectionType.Down:
- if (_startPosY.Value + EntityElectroTrans.Step < Config.screenSize.Height - 40)
+ if (_startPosY.Value + EntityElectroTrans.Step < _pictureHeight - 40)
{
_startPosY += (int)EntityElectroTrans.Step;
}
diff --git a/Lab1/Form1.Designer.cs b/Lab1/Form1.Designer.cs
index b3e3223..c38f581 100644
--- a/Lab1/Form1.Designer.cs
+++ b/Lab1/Form1.Designer.cs
@@ -53,7 +53,7 @@
buttonCreateSportCar.Name = "buttonCreateSportCar";
buttonCreateSportCar.Size = new Size(75, 23);
buttonCreateSportCar.TabIndex = 1;
- buttonCreateSportCar.Text = "Создать";
+ buttonCreateSportCar.Text = pictureBoxSportCar.ClientSize.ToString();
buttonCreateSportCar.UseVisualStyleBackColor = true;
buttonCreateSportCar.Click += ButtonCreateElectroTrans_Click;
//
diff --git a/Lab1/Form1.cs b/Lab1/Form1.cs
index db4f6e5..a2d8422 100644
--- a/Lab1/Form1.cs
+++ b/Lab1/Form1.cs
@@ -5,11 +5,12 @@ namespace Lab1
///
/// -
///
- private DrawingElectroTrans? _drawningElectroTrans;
+ private DrawingElectroTrans _drawningElectroTrans;
public Form1()
{
InitializeComponent();
+ _drawningElectroTrans = new DrawingElectroTrans();
}
///
@@ -30,15 +31,30 @@ namespace Lab1
private void ButtonCreateElectroTrans_Click(object sender, EventArgs e)
{
Random random = new();
- _drawningElectroTrans = new DrawingElectroTrans();
_drawningElectroTrans.Init(random.Next(500, 1500), 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)), random.Next(3, 8), Convert.ToBoolean(random.Next(0, 2)));
- _drawningElectroTrans.SetPictureSize(pictureBoxSportCar.Width, pictureBoxSportCar.Height);
+ SetSize();
_drawningElectroTrans.SetPosition(50, 50);
+ Resize += Form1_Resize;
Draw();
}
+
+ private void Form1_Resize(object? sender, EventArgs e)
+ {
+ SetSize();
+ }
+ private void SetSize()
+ {
+ if (!_drawningElectroTrans.SetPictureSize(ClientSize.Width, ClientSize.Height))
+ {
+ Size = Config.screenSize;
+ }
+ pictureBoxSportCar.Size = ClientSize;
+ buttonCreateSportCar.Text = ClientSize.ToString();
+ }
+
///
/// ( )
///