Лабараторная работа №1 v1.1

This commit is contained in:
Павел Ладягин 2024-02-21 16:34:26 +04:00
parent f38246d46d
commit 8b9f31abb3
3 changed files with 68 additions and 46 deletions

View File

@ -38,7 +38,7 @@
/// <summary> /// <summary>
/// Высота прорисовки самолета /// Высота прорисовки самолета
/// </summary> /// </summary>
public readonly int PlaneHeight = 95; public readonly int PlaneHeight = 110;
/// <summary> /// <summary>
@ -68,23 +68,33 @@
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns> /// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height) public bool SetPictureSize(int width, int height)
{ {
// TODO проверка, что объект "влезает" в размеры поля if (PlaneWidth < width && PlaneHeight < height)
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена {
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
//if (PlaneWidth < _pictureWidth || PlaneHeight < _pictureHeight) if(_startPosX != null && _startPosY != null)
//{ {
// return false; if(_startPosX.Value < 0)
//} {
//if ((_startPosX + PlaneWidth) < _pictureWidth) _startPosX = 0;
//{ }
// _startPosX -= PlaneWidth + _pictureWidth; if(_startPosY.Value < 0)
//} {
//if ((_startPosY + PlaneHeight) < _pictureHeight) _startPosY = 0;
//{ }
// _startPosY -= PlaneHeight + _pictureHeight;
//} if(_startPosX.Value + PlaneWidth > _pictureWidth)
return true; {
_startPosX = _pictureWidth - PlaneWidth;
}
if (_startPosY.Value + PlaneHeight > _pictureHeight)
{
_startPosY = _pictureHeight - PlaneHeight;
}
}
}
return false;
} }
/// <summary> /// <summary>
@ -98,22 +108,27 @@
{ {
return; return;
} }
//TODO (10:52)
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
//if (PlaneWidth < _pictureWidth || PlaneHeight < _pictureHeight)
//{
// return;
//}
//if ((_startPosX + PlaneWidth) < _pictureWidth)
//{
// _startPosX -= PlaneWidth + _pictureWidth;
//}
//if ((_startPosY + PlaneHeight) < _pictureHeight)
//{
// _startPosY -= PlaneHeight + _pictureHeight;
//}
if (_startPosX.Value < 0)
{
_startPosX = 0;
}
if(_startPosY.Value < 0)
{
_startPosY = 0;
}
if (_startPosX.Value + PlaneWidth > _pictureWidth)
{
_startPosX = _pictureWidth - PlaneWidth;
}
if (_startPosY.Value + PlaneHeight > _pictureHeight)
{
_startPosY = _pictureHeight - PlaneHeight;
}
} }
/// <summary> /// <summary>

View File

@ -41,17 +41,19 @@
// //
pictureBoxAirplaneWithRadar.Dock = DockStyle.Fill; pictureBoxAirplaneWithRadar.Dock = DockStyle.Fill;
pictureBoxAirplaneWithRadar.Location = new Point(0, 0); pictureBoxAirplaneWithRadar.Location = new Point(0, 0);
pictureBoxAirplaneWithRadar.Margin = new Padding(3, 4, 3, 4);
pictureBoxAirplaneWithRadar.Name = "pictureBoxAirplaneWithRadar"; pictureBoxAirplaneWithRadar.Name = "pictureBoxAirplaneWithRadar";
pictureBoxAirplaneWithRadar.Size = new Size(987, 477); pictureBoxAirplaneWithRadar.Size = new Size(1128, 636);
pictureBoxAirplaneWithRadar.TabIndex = 0; pictureBoxAirplaneWithRadar.TabIndex = 0;
pictureBoxAirplaneWithRadar.TabStop = false; pictureBoxAirplaneWithRadar.TabStop = false;
// //
// buttonCreate // buttonCreate
// //
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 442); buttonCreate.Location = new Point(14, 589);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate"; buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(75, 23); buttonCreate.Size = new Size(86, 31);
buttonCreate.TabIndex = 1; buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать"; buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true; buttonCreate.UseVisualStyleBackColor = true;
@ -62,9 +64,10 @@
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.Стрелка_влево; buttonLeft.BackgroundImage = Properties.Resources.Стрелка_влево;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(858, 430); buttonLeft.Location = new Point(981, 573);
buttonLeft.Margin = new Padding(3, 4, 3, 4);
buttonLeft.Name = "buttonLeft"; buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(35, 35); buttonLeft.Size = new Size(40, 47);
buttonLeft.TabIndex = 2; buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true; buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click; buttonLeft.Click += ButtonMove_Click;
@ -74,9 +77,10 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.Стрелка_вправо; buttonRight.BackgroundImage = Properties.Resources.Стрелка_вправо;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch; buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(940, 430); buttonRight.Location = new Point(1074, 573);
buttonRight.Margin = new Padding(3, 4, 3, 4);
buttonRight.Name = "buttonRight"; buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(35, 35); buttonRight.Size = new Size(40, 47);
buttonRight.TabIndex = 3; buttonRight.TabIndex = 3;
buttonRight.UseVisualStyleBackColor = true; buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click; buttonRight.Click += ButtonMove_Click;
@ -86,9 +90,10 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.Стрелка_вниз; buttonDown.BackgroundImage = Properties.Resources.Стрелка_вниз;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch; buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(899, 430); buttonDown.Location = new Point(1027, 573);
buttonDown.Margin = new Padding(3, 4, 3, 4);
buttonDown.Name = "buttonDown"; buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35); buttonDown.Size = new Size(40, 47);
buttonDown.TabIndex = 4; buttonDown.TabIndex = 4;
buttonDown.UseVisualStyleBackColor = true; buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click; buttonDown.Click += ButtonMove_Click;
@ -98,24 +103,26 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.Стрелка_вверх; buttonUp.BackgroundImage = Properties.Resources.Стрелка_вверх;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch; buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(899, 389); buttonUp.Location = new Point(1027, 519);
buttonUp.Margin = new Padding(3, 4, 3, 4);
buttonUp.Name = "buttonUp"; buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(35, 35); buttonUp.Size = new Size(40, 47);
buttonUp.TabIndex = 5; buttonUp.TabIndex = 5;
buttonUp.UseVisualStyleBackColor = true; buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click; buttonUp.Click += ButtonMove_Click;
// //
// FormAirplaneWithRadar // FormAirplaneWithRadar
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(987, 477); ClientSize = new Size(1128, 636);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonCreate); Controls.Add(buttonCreate);
Controls.Add(pictureBoxAirplaneWithRadar); Controls.Add(pictureBoxAirplaneWithRadar);
Margin = new Padding(3, 4, 3, 4);
Name = "FormAirplaneWithRadar"; Name = "FormAirplaneWithRadar";
Text = "Самолет с радаром"; Text = "Самолет с радаром";
((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).EndInit();

View File

@ -9,7 +9,7 @@
/// Поле-объект для происовки объект /// Поле-объект для происовки объект
/// </summary> /// </summary>
private DrawingAirplaneWithRadar? _drawingAirplaneWithRadar; private DrawingAirplaneWithRadar? _drawingAirplaneWithRadar;
/// <summary> /// <summary>
/// Конструктор формы /// Конструктор формы
/// </summary> /// </summary>
@ -91,6 +91,6 @@
UpdatePlane(); UpdatePlane();
} }
} }
} }
} }