我还有什么: Big PictureBox(让我们称之为Pic_Map)在窗体上。类Ore.cs
,A List<Ore> ores;
和一个数据库,它将数据提取并放入ores
列表中。在循环中添加控件(Picturebox)
功能:所以,这个功能是我有一个TextBox/Combobox和一个按钮。当我按下按钮时,它将通过ores
列表循环,并且基于等于数据的TexBox/ComboBox(在本例中为Ore_Name),在Pic_Map的顶部动态添加PictureBoxes。
问题:这一切工作正常,但问题是,当我加入PictureBoxes动态,似乎只添加ores
名单上的最后一个值(上Pic_Map红色圆圈)。所以,它最终只显示1个PictureBox,而不是让我们说3,因为我有3个与TextBox/ComboBox匹配的值名称。
问题:如何让它工作,就像我写/选择“Flame Stone”一样,它在名称中包含“Flame Stone”的所有数据上添加它(而不是仅添加最后一个来自列表中的值)。
代码:
private void PopulateComboBoxByName()
{
PictureBox ore_Area = new PictureBox();
db.GetOre(); //Getting data and putting it into "ores" list
foreach (Ore ore in db.ores)
{
if (CBOX_Filter.SelectedItem.ToString() == ore.Ore_Name)
{
int area_Width = Convert.ToInt32(ore.Area_Width);
int area_Height = Convert.ToInt32(ore.Area_Height);
int ore_Width = Convert.ToInt32(ore.Ore_Width);
int ore_Height = Convert.ToInt32(ore.Ore_Height) - area_Height/2;
ore_Area.Name = "ore_Area";
ore_Area.ImageLocation = @"Data\Images\Circle.png";
ore_Area.SizeMode = PictureBoxSizeMode.StretchImage;
ore_Area.Size = new Size(Convert.ToInt32(area_Width), Convert.ToInt32(area_Height));
ore_Area.Location = new Point(Convert.ToInt32(ore_Width), Convert.ToInt32(ore_Height));
ore_Area.BackColor = Color.Transparent;
this.Controls.Add(ore_Area);
}
}
ore_Area.Parent = PIC_Map;
}
图片:
这个位置是否总是一样? – LarsTech
是的,基本上“Image_Width”和“Image_Height”是放置图片框的表单的坐标。所以位置等可以是相同的,无所谓。 – SunnlightBro
你只创建一个PictureBox, – LarsTech