Hi ce2006121,
Welcome to MSDN Forum.
Please try the following code sample to randomly select an image from ImageList for PictureBox control.
Prerequisites: Drag ImageList1, PictureBox1 and Button1 onto Form1.
using System.Drawing;
publicpartialclassForm1 : Form
{
privatevoid button1_Click(object sender,EventArgs e)
{
Image img1 = Image.FromFile(@"C:\1.jpg");
Image img2 = Image.FromFile(@"C:\2.jpg");
imageList1.Images.AddRange(new Image[] { img1, img2 });
Random rnd = newRandom();
Image choice = imageList1.Images[rnd.Next(0, imageList1.Images.Count)];
pictureBox1.Image = choice;
}
}
Martin Xie [MSFT]
MSDN Community Support | Feedback to us