добавить изображение в windowsform c # - PullRequest
0 голосов
/ 29 декабря 2011

Я пытался добавить picturebox в windowsform при загрузке обработчика событий, но изображения не появлялись в форме после загрузки 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;
                }
            }
        } 

1 Ответ

3 голосов
/ 29 декабря 2011

Для добавления PictureBox или любого другого элемента управления:

PictureBox pic = new Picturebox();
this.Controls.Add(pic);
...