I am creating a simple form-based message display system, each message is a jpeg image, which I want to achieve when the program loads (immediately after user login) one of the jpg is randomly selected and shown, if the user clicks the "Next" button, it is still displayed one jpg until all are displayed. I think I need to read each image in the array, and then randomly select one from the array, and then, when the user clicks the "Next" button, go to the next element of the array. One of the caveats is that I do not want the program to block open jpg files, since others should be able to delete them.
My current code is below, I would appreciate any help and advice you can offer.
private void Form1_Load(object sender, EventArgs e)
{
var rand = new Random();
var files = Directory.GetFiles(@"\\server\screens\", "*.jpg");
pictureBox1.Image = System.Drawing.Bitmap.FromFile(files[rand.Next(files.Length)]);
}
private void buttonNextImage_Click(object sender, EventArgs e)
{
var rand = new Random();
var files = Directory.GetFiles(@"\\server\screens\", "*.jpg");
pictureBox1.Image = System.Drawing.Bitmap.FromFile(files[rand.Next(files.Length)]);
}
Thanks a lot Steven
source
share