更新时间:2022-11-08 22:04:22
如果你使用图像路线,您可以使用列表 images = new List ()创建图像列表;并使用images.Add(image)添加每个图像。对于每个图像。
If you're using the Image route, you can create a list of images with List images = new List(); and add each image to it with images.Add(image); for each image.
For Images:
Random random = new Random();
samplePictureBox.Image = images[random.Next(0, images.Count - 1)];
试试这个:
Try this:
private Random rand = new Random();
...
public void GetRandomImage()
{
string[] files = Directory.GetFiles(@"D:\Temp\", "*.jpg", SearchOption.AllDirectories);
myPictureBox.Image = Image.FromFile(files[rand.Next(files.Length)]);
}
0
和(List.Count-1)之间选择一个随机数 r
。 r
相对应的图像。r
, between 0
and (List.Count-1)
.r
of the list.