diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/DrawingAirplaneWithRadar.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/DrawingAirplaneWithRadar.cs index 7db7d69..2bd2021 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/DrawingAirplaneWithRadar.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/DrawingAirplaneWithRadar.cs @@ -38,7 +38,7 @@ /// /// Высота прорисовки самолета /// - public readonly int PlaneHeight = 95; + public readonly int PlaneHeight = 110; /// @@ -68,23 +68,33 @@ /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах public bool SetPictureSize(int width, int height) { - // TODO проверка, что объект "влезает" в размеры поля - // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена - _pictureWidth = width; - _pictureHeight = height; - //if (PlaneWidth < _pictureWidth || PlaneHeight < _pictureHeight) - //{ - // return false; - //} - //if ((_startPosX + PlaneWidth) < _pictureWidth) - //{ - // _startPosX -= PlaneWidth + _pictureWidth; - //} - //if ((_startPosY + PlaneHeight) < _pictureHeight) - //{ - // _startPosY -= PlaneHeight + _pictureHeight; - //} - return true; + if (PlaneWidth < width && PlaneHeight < height) + { + _pictureWidth = width; + _pictureHeight = height; + if(_startPosX != null && _startPosY != null) + { + 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; + } + } + } + + return false; } /// @@ -98,22 +108,27 @@ { return; } - //TODO (10:52) + _startPosX = x; _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; + } } /// diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.Designer.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.Designer.cs index 0206783..2ed78dd 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.Designer.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.Designer.cs @@ -41,17 +41,19 @@ // pictureBoxAirplaneWithRadar.Dock = DockStyle.Fill; pictureBoxAirplaneWithRadar.Location = new Point(0, 0); + pictureBoxAirplaneWithRadar.Margin = new Padding(3, 4, 3, 4); pictureBoxAirplaneWithRadar.Name = "pictureBoxAirplaneWithRadar"; - pictureBoxAirplaneWithRadar.Size = new Size(987, 477); + pictureBoxAirplaneWithRadar.Size = new Size(1128, 636); pictureBoxAirplaneWithRadar.TabIndex = 0; pictureBoxAirplaneWithRadar.TabStop = false; // // buttonCreate // 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.Size = new Size(75, 23); + buttonCreate.Size = new Size(86, 31); buttonCreate.TabIndex = 1; buttonCreate.Text = "Создать"; buttonCreate.UseVisualStyleBackColor = true; @@ -62,9 +64,10 @@ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = Properties.Resources.Стрелка_влево; 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.Size = new Size(35, 35); + buttonLeft.Size = new Size(40, 47); buttonLeft.TabIndex = 2; buttonLeft.UseVisualStyleBackColor = true; buttonLeft.Click += ButtonMove_Click; @@ -74,9 +77,10 @@ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = Properties.Resources.Стрелка_вправо; 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.Size = new Size(35, 35); + buttonRight.Size = new Size(40, 47); buttonRight.TabIndex = 3; buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; @@ -86,9 +90,10 @@ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = Properties.Resources.Стрелка_вниз; 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.Size = new Size(35, 35); + buttonDown.Size = new Size(40, 47); buttonDown.TabIndex = 4; buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += ButtonMove_Click; @@ -98,24 +103,26 @@ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = Properties.Resources.Стрелка_вверх; 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.Size = new Size(35, 35); + buttonUp.Size = new Size(40, 47); buttonUp.TabIndex = 5; buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // // FormAirplaneWithRadar // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(987, 477); + ClientSize = new Size(1128, 636); Controls.Add(buttonUp); Controls.Add(buttonDown); Controls.Add(buttonRight); Controls.Add(buttonLeft); Controls.Add(buttonCreate); Controls.Add(pictureBoxAirplaneWithRadar); + Margin = new Padding(3, 4, 3, 4); Name = "FormAirplaneWithRadar"; Text = "Самолет с радаром"; ((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).EndInit(); diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs index 6642d98..7ec64fb 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs @@ -9,7 +9,7 @@ /// Поле-объект для происовки объект /// private DrawingAirplaneWithRadar? _drawingAirplaneWithRadar; - + /// /// Конструктор формы /// @@ -91,6 +91,6 @@ UpdatePlane(); } - } + } } }