Готовая 4 лаба!

This commit is contained in:
platoff aeeee 2023-11-08 09:24:14 +04:00
parent 270c3d7d4f
commit b906b3f880
4 changed files with 15 additions and 10 deletions

View File

@ -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
//

View File

@ -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();
}
}
}

View File

@ -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;

View File

@ -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);
}