Изменено направление вывода объектов на форме с коллекцией объектов

This commit is contained in:
Никита Потапов 2023-10-10 11:59:02 +04:00
parent f652dfcd18
commit 45c7fb8ab3
2 changed files with 11 additions and 10 deletions

View File

@ -46,7 +46,7 @@
pictureBoxStormtrooper.Dock = DockStyle.Fill;
pictureBoxStormtrooper.Location = new Point(0, 0);
pictureBoxStormtrooper.Name = "pictureBoxStormtrooper";
pictureBoxStormtrooper.Size = new Size(1043, 546);
pictureBoxStormtrooper.Size = new Size(948, 546);
pictureBoxStormtrooper.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxStormtrooper.TabIndex = 0;
pictureBoxStormtrooper.TabStop = false;
@ -67,7 +67,7 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUP;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.Location = new Point(965, 468);
buttonUp.Location = new Point(870, 468);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(30, 30);
buttonUp.TabIndex = 2;
@ -79,7 +79,7 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDOWN;
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.Location = new Point(965, 504);
buttonDown.Location = new Point(870, 504);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(30, 30);
buttonDown.TabIndex = 3;
@ -91,7 +91,7 @@
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLEFT;
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.Location = new Point(929, 504);
buttonLeft.Location = new Point(834, 504);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(30, 30);
buttonLeft.TabIndex = 4;
@ -103,7 +103,7 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRIGHT;
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.Location = new Point(1001, 504);
buttonRight.Location = new Point(906, 504);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(30, 30);
buttonRight.TabIndex = 5;
@ -127,7 +127,7 @@
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToRightBottom" });
comboBoxStrategy.Location = new Point(880, 12);
comboBoxStrategy.Location = new Point(785, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.TabIndex = 7;
@ -135,7 +135,7 @@
// buttonStep
//
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonStep.Location = new Point(937, 46);
buttonStep.Location = new Point(842, 46);
buttonStep.Name = "buttonStep";
buttonStep.Size = new Size(94, 29);
buttonStep.TabIndex = 8;
@ -157,7 +157,7 @@
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1043, 546);
ClientSize = new Size(948, 546);
Controls.Add(buttonSelectPlane);
Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy);

View File

@ -116,14 +116,15 @@ namespace ProjectStormtrooper
private void DrawObjects(Graphics g)
{
int placesColumnCount = _pictureHeight / _placeSizeHeight;
int placesRowCount = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count; i++)
{
// получение объекта
var obj = _collection.Get(i);
// установка позиции
obj?.SetPosition(
(int)(i / placesColumnCount * _placeSizeWidth + (_placeSizeWidth - obj?.GetWidth) / 2),
(int)(i % placesColumnCount * _placeSizeHeight + (_placeSizeHeight - obj?.GetHeight) / 2)
(int)((placesRowCount - 1) * _placeSizeWidth - (i % placesColumnCount * _placeSizeWidth) + (_placeSizeWidth - obj?.GetWidth) / 2),
(int)(i / placesColumnCount * _placeSizeHeight + (_placeSizeHeight - obj?.GetHeight) / 2)
);
// прорисовка объекта
obj?.DrawTransport(g);