Изменение проверок в установке позиции объекта.

This commit is contained in:
Anastasia 2022-10-04 13:55:27 +04:00
parent 0832085f20
commit 70cbb4b989
3 changed files with 21 additions and 21 deletions

View File

@ -59,25 +59,27 @@ namespace AirplaneWithRadar
/// <param name="height">Высота картинки</param>
public void SetPosition(int x, int y, int width, int height)
{
// TODO проверки
if (x > 0 && x < width)
if (x > 0 && x < width && x + _airplaneWidth < width)
{
_startPosX = x;
}
if (y > 0 && y < height)
if (y > 0 && y < height && y + _airplaneHeight < height)
{
_startPosY = y;
}
if (width > 0)
}
if (width > 0 && width > _airplaneWidth)
{
_pictureWidth = width;
}
if (height > 0)
if (height > 0 && height > _airplaneHeight)
{
_pictureHeight = height;
}
}
}
/// <summary>
/// Изменение направления перемещения
@ -127,8 +129,7 @@ namespace AirplaneWithRadar
/// <param name="g"></param>
public void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}

View File

@ -81,7 +81,7 @@
this.pictureBoxAirplane.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxAirplane.TabIndex = 1;
this.pictureBoxAirplane.TabStop = false;
this.pictureBoxAirplane.Click += new System.EventHandler(this.pictureBoxAirplane_Click);
//
// buttonCreate
//

View File

@ -30,8 +30,7 @@ namespace AirplaneWithRadar
_airplane = new DrawingAirplane();
_airplane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxAirplane.Width, pictureBoxAirplane.Height);
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),pictureBoxAirplane.Width, pictureBoxAirplane.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airplane.Airplane.BodyColor.Name}";
@ -58,20 +57,20 @@ namespace AirplaneWithRadar
break;
}
Draw();
}
private void FormAirplaneWithRadar_Load(object sender, EventArgs e)
/// <summary>
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBoxAirplane_Resize(object sender, EventArgs e)
{
_airplane?.ChangeBorders(pictureBoxAirplane.Width, pictureBoxAirplane.Height);
Draw();
}
private void pictureBoxAirplane_Click(object sender, EventArgs e)
{
}
}
}