Rob
Rob

Reputation: 109

C#, dynamically creating picture boxes?

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!

Upvotes: 1

Views: 14114

Answers (3)

Fredou
Fredou

Reputation: 20140

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)

Upvotes: 1

SLaks
SLaks

Reputation: 888283

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

Upvotes: 1

Kieren Johnstone
Kieren Johnstone

Reputation: 42023

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.

Upvotes: 3

Related Questions