Select several random values from the data array in the form of images
Please tell the novice, you need to select several random values from the data array and output them as images
How do I bind an image to each value in an array or dictionary and then output it to the "piccherbox"?
That's how it turned out to display a random image at the click of a button.
string[] food = new string[] { "Donut", "bread", "water" };
string randomfood = food[new Random().Next(0, Champ.Length)];
textBox2.Text = randomfood;
if (randomChamp == "Donut")
{
pictureBox2.Image = Properties.Resources.Donut_0;
}
if (randomChamp == "bread")
{
pictureBox2.Image = Properties.Resources.bread_0;
}
if (randomChamp == "water")
{
pictureBox2.Image = Properties.Resources.water_0;
0
1 answers
You will need to name your images in the resources exactly as they are named in the array of keys food
string[] food = new string[] { "Donut", "bread", "water" };
string randomfood = food[new Random().Next(0, Champ.Length)];
pictureBox2.Image = (Bitmap)Properties.Resources.ResourceManager.GetObject(randomfood)
0
Author: Pavel Popov, 2020-08-24 15:45:57