title: C# display images randomly and one after another
body: <p>I am creating a simple form based message display system, each message is a jpeg image, what I want to achieve is when the program loads (just after a user has logged on) one of the jpg's is randomly selected and shown, if the user clicks the Next button another jpg is shown until all have been displayed. I think I need to read each image into an array and then randomly select one from the array and then when a user clicks Next move on to the next item in the array. One caveat is that I don't want the program to lock open the jpg files as others need to be able to delete them. </p>
  
  <p>My current code is below, I would appreciate any help and advice you can offer.</p>
  
  <pre><code>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)]);
   }
  </code></pre>
  
  <p>Many thanks
  Steven</p>