Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
change image randomly on mouse click
Posted

Use the class Random; everything else depends on your requirements, but it should not be hard to do.
—SA
 
Share this answer
 
Hi Chaitanya, I have show 2 examples here. Pick which is best for you

C#
List<Image> imageLst = new List<Image>();
            imageLst.Add(image);

            //Show the image on Picbox
            Random random = new Random();
            pictureBox1.Image = imageLst[random.Next(0, images.Count - 1)];

            //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

            //if you want to import from a path
            List<String> imagePathList = new List<String>();
            imagePathList.Add(imagePath);

            //Show the image on Picbox
            Random random = new Random();
            pictureBox1.ImageLocation = imagePathList[random.Next(0, images.Count - 1)];
 
Share this answer
 
v2

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