0
Reply

PictureBox.Image assignment at runtime not working

tom 0

tom 0

Nov 17 2004 8:02 PM
1.8k
I have a 10 x 10 array of PictureBox images. I want to change the image for any PictureBox in the array at runtime. For some reason the Image is not refreshing after assignment. Complete C# source code is located here: http://www.robotzgame.com/junk/robotz.zip ======================================== Here are the relevant bits of code: public void ClearGameBoard() { foreach (Control c in this.Controls) { if (c is System.Windows.Forms.PictureBox) { System.Windows.Forms.PictureBox pb = (System.Windows.Forms.PictureBox) c; this.Controls.Remove(pb); } } } public void ClearPBoxArray() { ClearGameBoard(); for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { pBoxArray[i,j] = null; } } } public void UpdateGameBoard() { //ClearPBoxArray(); //ClearGameBoard(); for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { pBoxArray[i,j] = new System.Windows.Forms.PictureBox(); pBoxArray[i,j].Image = gw.gamePieceArray[i,j].pic_box.Image; pBoxArray[i,j].Location=new Point(i*32,j*32); pBoxArray[i,j].Size=new Size(32,32); pBoxArray[i,j].Tag=new Point(i,j); pBoxArray[i,j].Click += new System.EventHandler(pictureClick); pBoxArray[i,j].MouseEnter += new System.EventHandler(pictureMouseEnter); pBoxArray[i,j].MouseLeave += new System.EventHandler(pictureMouseLeave); this.Controls.Add(pBoxArray[i,j]); } } }