Reputation:
I'm new to programming in C#. My question is this;
how can i, after generating random numbers (i got so far), get these numbers to show random images in imageboxes?
I have 4 imageboxes with a backgroundimage. (but i want them to change, according to the numbers i generate).
How do i do that?
Anybody got an idea?
Thx in advance!!
Upvotes: 0
Views: 160
Reputation: 50273
Put the imageboxes in an array, then use the random number as the index of the array to get a random imagebox.
Upvotes: 3
Reputation: 1499770
Keep a list of images, and set the image to a random element in the list:
public class SomeHostingForm
{
private readonly List<Image> images; // Populate elsewhere...
private readonly Random random = new Random();
private void SwitchImage(ImageBox box)
{
box.Image = images[random.Next(images.Count)];
}
}
(I'm not sure exactly which type you're talking about, so this is somewhat pseudo-code.)
Upvotes: 7