public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
FileInfo[] fileInfo;
List<image> imgList;
private void Form1_Load(object sender, EventArgs e)
{
DirectoryInfo drInfo = new DirectoryInfo("Images");
fileInfo = drInfo.GetFiles("*.jpg");
imgList = new List<image>();
foreach (var item in fileInfo)
{
imgList.Add(Image.FromFile(item.FullName));
}
}
Random rnd = new Random();
private Image RandomPicButton()
{
int rndNumber = rnd.Next(imgList.Count);
return imgList[rndNumber];
}
private void randomCLick(object sender, EventArgs e)
{
button9.Image = RandomPicButton();
button10.Image = RandomPicButton();
button13.Image = RandomPicButton();
button14.Image = RandomPicButton();
}
}
</image></image>
This Work. One Event to All buttons.
It is interesting if Random put inside RandomPicButton() it return the same picture.
I learning C#, so comments about my code are welcomed