我尝试在Windows窗体中添加picturebox onload event-handler,但加载后图片没有出现在窗体中
attachimage
是我从工具箱中添加的图片框(不是通过c#)
private void ViewCmap_Load(object sender, EventArgs e)
{
for (int i = 0; i < ConceptProperties.ConceptsMap.Count; i++)
{
conceptattchboxlist.Add(new PictureBox());
conceptattchboxlist[i].Visible = true;
if (ConceptProperties.ConceptsMap[i].Attachments.Count > 0)
{
PictureBox new_attach_box = new PictureBox();
new_attach_box.Image = attachimage.Image;
new_attach_box.Width = attachimage.Width;
new_attach_box.Height = attachimage.Height;
new_attach_box.BackgroundImageLayout = ImageLayout.Stretch;
new_attach_box.SizeMode = PictureBoxSizeMode.StretchImage;
new_attach_box.Location = new Point(ConceptProperties.ConceptsMap[i].Coords[0] + (ConceptProperties.ConceptsMap[i].Coords[2]), ConceptProperties.ConceptsMap[i].Coords[1] + (ConceptProperties.ConceptsMap[i].Coords[3]));
conceptattchboxlist[i] = new_attach_box;
}
}
for (int i = 0; i < ConceptProperties.ConnectionMap.Count; i++)
{
connectionattchboxlist.Add(new PictureBox());
connectionattchboxlist[i].Visible = true;
if (ConceptProperties.ConnectionMap[i].Attachments.Count > 0)
{
PictureBox new_attach_box = new PictureBox();
new_attach_box.Image = attachimage.Image;
new_attach_box.Width = attachimage.Width;
new_attach_box.Height = attachimage.Height;
new_attach_box.BackgroundImageLayout = ImageLayout.Stretch;
new_attach_box.SizeMode = PictureBoxSizeMode.StretchImage;
new_attach_box.Location = new Point(ConceptProperties.ConceptsMap[i].Coords[0] + (ConceptProperties.ConceptsMap[i].Coords[2]), ConceptProperties.ConceptsMap[i].Coords[1] + (ConceptProperties.ConceptsMap[i].Coords[3]));
new_attach_box.Show();
connectionattchboxlist[i] = new_attach_box;
}
}
}
答案 0 :(得分:3)
添加pictureBox或任何控件使用:
PictureBox pic = new Picturebox();
this.Controls.Add(pic);