Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3671370
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:28:44+00:00 2026-05-19T02:28:44+00:00

I am creating a simple form based message display system, each message is a

  • 0

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.

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)]);
 }

Many thanks
Steven

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:28:45+00:00Added an answer on May 19, 2026 at 2:28 am

    Don’t use Bitmap.FromFile, use Bitmap.FromStream:

    using(var fs = new FileStream(files[rand.Next(files.Length),
                                  FileMode.Open, FileAccess.Read))
    {
        pictureBox1.Image = System.Drawing.Bitmap.FromStream(fs);
    }
    

    I don’t know how to create an array of images

    var files = Directory.GetFiles("\\\\server\\screens\\", "*.jpg");
    var images = new Image[files.Length];
    for(int i = 0; i < files.Length; ++i)
    {
        using(var fs = new FileStream(files[i], FileMode.Open, FileAccess.Read))
        {
            images[i] = System.Drawing.Image.FromStream(fs);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a simple API that creates typed classes based on JSON data that
I'm creating a simple tag system that allows me to link a tag to
One simple method I've used in the past is basically just creating a second
I'm creating a threaded message board and I'm trying to keep it simple. There's
I'm creating a .vdproj setup for a simple Windows form. I have added a
I am using Visual Studio 2008 Express and I tried creating a simple console
The issue is simple really. Instead of creating folders in Visual Studio, I create
I have a simple form which inserts a new Category with the given parentID
basically i'm creating a tariff calculator for a utility company in my country, based
I remember it is possible to stop a website in IIS simply creating a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.