From b906b3f8800ef3db9284d27ccfc1f56c218dd960 Mon Sep 17 00:00:00 2001 From: platoff aeeee Date: Wed, 8 Nov 2023 09:24:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=204?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=B0!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/Tank/FormArmoredCarCollection.Designer.cs | 1 + Tank/Tank/FormArmoredCarCollection.cs | 18 ++++++++++++------ Tank/Tank/Generics/SetGeneric.cs | 4 +--- Tank/Tank/Generics/TanksGenericCollection.cs | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Tank/Tank/FormArmoredCarCollection.Designer.cs b/Tank/Tank/FormArmoredCarCollection.Designer.cs index be4dcf2..1230437 100644 --- a/Tank/Tank/FormArmoredCarCollection.Designer.cs +++ b/Tank/Tank/FormArmoredCarCollection.Designer.cs @@ -86,6 +86,7 @@ this.listBoxStorages.Name = "listBoxStorages"; this.listBoxStorages.Size = new System.Drawing.Size(129, 94); this.listBoxStorages.TabIndex = 6; + this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxStorages_SelectedIndexChanged); // // ButtonDelObject // diff --git a/Tank/Tank/FormArmoredCarCollection.cs b/Tank/Tank/FormArmoredCarCollection.cs index 1f4c749..cd95538 100644 --- a/Tank/Tank/FormArmoredCarCollection.cs +++ b/Tank/Tank/FormArmoredCarCollection.cs @@ -92,8 +92,7 @@ namespace Tank MessageBox.Show("Не удалось удалить объект"); } } - - private void ButtonRefreshCollection_Click(object sender, EventArgs e) + public void RefreshCollection() { if (listBoxStorages.SelectedIndex == -1) { @@ -108,6 +107,11 @@ namespace Tank pictureBoxCollection.Image = obj.ShowTanks(); } + private void ButtonRefreshCollection_Click(object sender, EventArgs e) + { + RefreshCollection(); + } + private void ButtonAddObject_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxStorageName.Text)) @@ -119,10 +123,6 @@ namespace Tank ReloadObjects(); } - private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e) - { - pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowTanks(); - } private void ButtonDelObject_Click(object sender, EventArgs e) { @@ -137,5 +137,11 @@ namespace Tank ReloadObjects(); } } + + private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) + { + pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowTanks(); + RefreshCollection(); + } } } diff --git a/Tank/Tank/Generics/SetGeneric.cs b/Tank/Tank/Generics/SetGeneric.cs index 1ca70c9..20b579d 100644 --- a/Tank/Tank/Generics/SetGeneric.cs +++ b/Tank/Tank/Generics/SetGeneric.cs @@ -29,9 +29,7 @@ namespace Tank.Generics public bool Insert(T tank, int position) { - if (position < 0) - return false; - if (Count >= _maxCount) + if (position < 0 || position > _maxCount) return false; _places.Insert(0, tank); return true; diff --git a/Tank/Tank/Generics/TanksGenericCollection.cs b/Tank/Tank/Generics/TanksGenericCollection.cs index 7354c5f..ff0838f 100644 --- a/Tank/Tank/Generics/TanksGenericCollection.cs +++ b/Tank/Tank/Generics/TanksGenericCollection.cs @@ -134,7 +134,7 @@ namespace Tank.Generics if (tank != null) { tank.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, - i % (_pictureWidth / _placeSizeWidth)); + (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight); tank.DrawTransport(g); }