I Want the program get a pic of user ,then convert image to puzzle (for example 100 piece) then make 100 picture box.
I using this following code for 4 and 9 piece.
if (Image_Num.SelectedIndex == 0)
{
PB = new PictureBox[4];
int W, H;
var imgarray = new Image[4];
var img = User_Image.Image;
W = img.Width / 2;
H = img.Height / 2;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
var index = i * 2 + j;
imgarray[index] = new Bitmap(W, H);
var graphics = Graphics.FromImage(imgarray[index]);
graphics.DrawImage(img, new Rectangle(0, 0, W, H), new Rectangle(i * W, j * H, W, H), GraphicsUnit.Pixel);
graphics.Dispose();
}
}
PB[0] = new PictureBox
{
Name = "P1",
Size = new Size(100, 100),
Location = new Point(394, 60),
Image = imgarray[0],
SizeMode = PictureBoxSizeMode.StretchImage
};
...
PB[0].MouseEnter += Images_M_E;
...
PB[0].MouseLeave += Images_M_L;
...
PB[0].MouseClick += Images_C;
...
Controls.Add(PB[0]);
...
}
I can't do this for 100 times or more.
Thanks.