Dynamic picturebox allocation
-
I am creating n pictureboxes and then setting a different image on each one of them in a loop. The user clicks on open n opens a .zip file (containing images only). I am unzipping the .zip contents in a folder and am able to extract the images from there.For the first time the pictureboxes rightly shows the images. But when again user click on the open button and select a .zip file to be opened. The new images doesnt appear completely. Problem could be: previous images are not getting removed so are not allowing the new images to appear. Language: c# code:
pb = new PictureBox[r*c];
Point point = new Point(100, 100);//pb.Image = null; for (i = 0; i < r \* c; i++) { pb\[i\] = new PictureBox(); { pb\[i\].Dispose(); } pb\[i\].Image = null; } int w = 800 / r; int k = 0; int h = 700 / c; int a = w, b = h; for (i1 = 0; i1 < r; i1++) { b = 15; for (i2 = 0; i2 < c; i2++) { // this.TransparencyKey = Color.Transparent; //pb.BackColor = Color.Transparent; pb\[k\] = new PictureBox(); pb\[k\].Image = null; pb\[k\].Size = new Size(w, h); this.Controls.Add(pb\[k\]); if (i1 == 0 ) { pb\[k\].Location = new Point(10, b); } else { pb\[k\].Location = new Point(a, b); } //a = a + w; b = b + h; Bitmap img=new Bitmap("d:\\\\puzzlesolver\\\\pieces\\\\piece"+i2.ToString()+i1.ToString()+".png"); Bitmap img1 = new Bitmap(img); pb\[k\].Image = img1; pb\[k\].SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; pb\[k++\].Update(); this.Update(); // img.Dispose(); } a = a + w; } this.Update();
I have tried a lot of things please tell me how to remove the existing picture boxes which are dynamically allocated and then add them ag
-
I am creating n pictureboxes and then setting a different image on each one of them in a loop. The user clicks on open n opens a .zip file (containing images only). I am unzipping the .zip contents in a folder and am able to extract the images from there.For the first time the pictureboxes rightly shows the images. But when again user click on the open button and select a .zip file to be opened. The new images doesnt appear completely. Problem could be: previous images are not getting removed so are not allowing the new images to appear. Language: c# code:
pb = new PictureBox[r*c];
Point point = new Point(100, 100);//pb.Image = null; for (i = 0; i < r \* c; i++) { pb\[i\] = new PictureBox(); { pb\[i\].Dispose(); } pb\[i\].Image = null; } int w = 800 / r; int k = 0; int h = 700 / c; int a = w, b = h; for (i1 = 0; i1 < r; i1++) { b = 15; for (i2 = 0; i2 < c; i2++) { // this.TransparencyKey = Color.Transparent; //pb.BackColor = Color.Transparent; pb\[k\] = new PictureBox(); pb\[k\].Image = null; pb\[k\].Size = new Size(w, h); this.Controls.Add(pb\[k\]); if (i1 == 0 ) { pb\[k\].Location = new Point(10, b); } else { pb\[k\].Location = new Point(a, b); } //a = a + w; b = b + h; Bitmap img=new Bitmap("d:\\\\puzzlesolver\\\\pieces\\\\piece"+i2.ToString()+i1.ToString()+".png"); Bitmap img1 = new Bitmap(img); pb\[k\].Image = img1; pb\[k\].SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; pb\[k++\].Update(); this.Update(); // img.Dispose(); } a = a + w; } this.Update();
I have tried a lot of things please tell me how to remove the existing picture boxes which are dynamically allocated and then add them ag
-
I am creating n pictureboxes and then setting a different image on each one of them in a loop. The user clicks on open n opens a .zip file (containing images only). I am unzipping the .zip contents in a folder and am able to extract the images from there.For the first time the pictureboxes rightly shows the images. But when again user click on the open button and select a .zip file to be opened. The new images doesnt appear completely. Problem could be: previous images are not getting removed so are not allowing the new images to appear. Language: c# code:
pb = new PictureBox[r*c];
Point point = new Point(100, 100);//pb.Image = null; for (i = 0; i < r \* c; i++) { pb\[i\] = new PictureBox(); { pb\[i\].Dispose(); } pb\[i\].Image = null; } int w = 800 / r; int k = 0; int h = 700 / c; int a = w, b = h; for (i1 = 0; i1 < r; i1++) { b = 15; for (i2 = 0; i2 < c; i2++) { // this.TransparencyKey = Color.Transparent; //pb.BackColor = Color.Transparent; pb\[k\] = new PictureBox(); pb\[k\].Image = null; pb\[k\].Size = new Size(w, h); this.Controls.Add(pb\[k\]); if (i1 == 0 ) { pb\[k\].Location = new Point(10, b); } else { pb\[k\].Location = new Point(a, b); } //a = a + w; b = b + h; Bitmap img=new Bitmap("d:\\\\puzzlesolver\\\\pieces\\\\piece"+i2.ToString()+i1.ToString()+".png"); Bitmap img1 = new Bitmap(img); pb\[k\].Image = img1; pb\[k\].SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; pb\[k++\].Update(); this.Update(); // img.Dispose(); } a = a + w; } this.Update();
I have tried a lot of things please tell me how to remove the existing picture boxes which are dynamically allocated and then add them ag
for (i = 0; i < r * c; i++)
{
pb[i] = new PictureBox();
{
pb[i].Dispose();
}pb\[i\].Image = null;
}
This is almost certainly not doing what you expect. You are creating new PictureBoxes and immediately Disposing them.
this.Controls.Add(pb[k]);
Every control added to a Form stay on the form until you call this.Controls.Remove with the same control. Disposing the control before removing it from the form may cause an exception, so make sure you do it in the right order.
-
You should not push people to reply to your question. Either the person who knows what is the problem hasn't seen it yet, or nobody knows. Exercise a little patience.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
-
for (i = 0; i < r * c; i++)
{
pb[i] = new PictureBox();
{
pb[i].Dispose();
}pb\[i\].Image = null;
}
This is almost certainly not doing what you expect. You are creating new PictureBoxes and immediately Disposing them.
this.Controls.Add(pb[k]);
Every control added to a Form stay on the form until you call this.Controls.Remove with the same control. Disposing the control before removing it from the form may cause an exception, so make sure you do it in the right order.