I am working on a puzzle slider program and trying to randomize images inside pictures. I did some research on the Internet, I canβt find examples that I could work on. This is my code:
Random r = new Random();
PictureBox[] picBox = new PictureBox[9];
picBox[0] = new PictureBox();
picBox[1] = new PictureBox();
picBox[2] = new PictureBox();
picBox[3] = new PictureBox();
picBox[4] = new PictureBox();
picBox[5] = new PictureBox();
picBox[6] = new PictureBox();
picBox[7] = new PictureBox();
picBox[8] = new PictureBox();
I also have an array of bitmap:
Bitmap[] pictures = new Bitmap[9];
pictures[0] = new Bitmap(@"1.1Bright.jpg");
pictures[1] = new Bitmap(@"1.2Bright.jpg");
pictures[2] = new Bitmap(@"1.3Bright.jpg");
pictures[3] = new Bitmap(@"2.1Bright.jpg");
pictures[4] = new Bitmap(@"2.2Bright.jpg");
pictures[5] = new Bitmap(@"2.3Bright.jpg");
pictures[6] = new Bitmap(@"3.1Bright.jpg");
pictures[7] = new Bitmap(@"3.2Bright.jpg");
pictures[8] = new Bitmap(@"3.3Dark.jpg");
I tried several ways, but I donβt know how to set random snapshots [] in picBox []:
for(int i=0; i<=8;i++)
{
picBox[i].Image= pictures[r.Next(0,9)];
}
the problem is that some graphic boxes, for example picBox [1] and picBox [6], are duplicate images. How to make them not repetitions? The examples are very grateful.
source
share