Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Picturebox in Visual CSharp

$
0
0
Hello, I just have a question. How can I shorten my code? It is intended to randomize the images in the 3 picturebox. (i'm doing the slot machine program with this..) Here's my code:

            int number1;
            int number2;
            int number3;
            Random randomize = new Random();
            number1 = randomize.Next(1,4);
            number2 = randomize.Next(1,4);
            number3 = randomize.Next(1,4);

            switch (number1)
            { 
                case 1:
                    pictureBox1.Image = new Bitmap("C:/Users/Public/Pictures/Sample Pictures/Paper.jpg");
                    break;
                case 2:
                    pictureBox1.Image = new Bitmap("C:/Users/Public/Pictures/Sample Pictures/Rock.jpg");
                    break;
                case 3:
                    pictureBox1.Image = new Bitmap("C:/Users/Public/Pictures/Sample Pictures/scissor.jpg");
                    break;
            }
            switch (number2)
            {
                case 1:
                    pictureBox2.Image = new Bitmap("C:/Users/Public/Pictures/Sample Pictures/Paper.jpg");
                    break;
                case 2:
                    pictureBox2.Image = new Bitmap("C:/Users/Public/Pictures/Sample Pictures/Rock.jpg");
                    break;
                case 3:
                    pictureBox2.Image = new Bitmap("C:/Users/Public/Pictures/Sample Pictures/scissor.jpg");
                    break;
            }
            switch (number3)
            {
                case 1:
                    pictureBox3.Image = new Bitmap("C:/Users/Public/Pictures/Sample Pictures/Paper.jpg");
                    break;
                case 2:
                    pictureBox3.Image = new Bitmap("C:/Users/Public/Pictures/Sample Pictures/Rock.jpg");
                    break;
                case 3:
                    pictureBox3.Image = new Bitmap("C:/Users/Public/Pictures/Sample Pictures/scissor.jpg");
                    break;
            }



Any suggestion? I'm new with randomizing pictures in vb so...just bear with it.
Please help me understand it more. Thanks a lot! :)

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>