string[] files = Directory.GetFiles("path");
int size = files.Length;
int index = new Random().Next(0,size);
string file = files[index];
int size = files.Length;
int index = new Random().Next(0,size);
string file = files[index];
如果想12张图片都显示,就是没有重复的,那就要先将12张图片文件名放到一个数组里面,然后随机取数组里面的数放到一个新的数组里面,如果新的数组里面已包含,就在原先的数组里面将其排除,然后再随机取,直到完成,再循环新数组里面的值给picturebox,OK。
{
string[] a = Directory.GetFiles(Directory.GetCurrentDirectory());
Int32 random = new Random().Next(0, a.Length);
this.pictureBox1.Load(Directory.GetCurrentDirectory() + a[random]);
}