Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to display images randomly when click Next button option. i created a form with 5 picturebox if i click next btn it will show pics randomly
Posted

It's difficult to be precise, wtihout knowing more about your application, and how you store your images, but assuming they are in a folder:
C#
private Random rand = new Random();
private Image GetRandomImage( string myImageFolderPath )
    {
    string[] files = Directory.GetFiles(myImageFolderPath);
    int i = rand.Next(files.Length);
    return Image.FromFile(files[i]);
    }
 
Share this answer
 
Hi,
Name your pictures accordingly (ending with image_1, image_2, image_3, etc.). Then change the URL to the ImageUrl with a random object:
C#
Random rand = new Random();
pictureBox.ImageUrl = "Your URL" + "\\image_" + rand.Next(1,6);

Kind regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900