1

For example I use a loop to create a list of "bird" objects with certain parameters. But I also need each bird object to have a pictureBox on the winform, any ideas, how do I do that, i.e. dynamically create and later delete a pictureBox?

Thanks!

Rob
  • 109
  • 2
  • 5
  • 7

3 Answers3

3

Here's the first result from googling your question title, which has an example of this:

http://www.dreamincode.net/forums/topic/78037-dynamically-create-multiple-picture-boxes/

Another: http://thechaosrift.com/viewtopic.php?f=32&t=4387&p=51006

Did you try something already and have a problem? If not, it's always worth consulting Google to see if you can learn on your own first.

Kieren Johnstone
  • 41,277
  • 16
  • 94
  • 144
1

pseudo code:

 list<picturebox>

 Instantiate the one needed 

 Initialize every picturebox that are needed

 Add them to the form (form.control.add)

 If needed remove them from the form, (form.control.remove)
Dfranc3373
  • 2,048
  • 4
  • 30
  • 44
Fredou
  • 19,848
  • 10
  • 58
  • 113
  • That's Pseudo, PictureBox, List, Controls.Add, Controls.Remove. And you can't initialise a PictureBox without first instantiating it. :/ – Kieren Johnstone Jan 31 '11 at 16:11
  • @Kieren Johnstone, I would assume that s/he would know that :-) but i will add it anyway – Fredou Jan 31 '11 at 16:13
1

You can create a new PictureBox instance, set its properties, and add it to the Controls collection of a form or panel.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964