Jerry Fike

Jerry Fike

  • NA
  • 107
  • 0

Another Newbie Queastion

Nov 5 2010 10:31 PM
I've been trying to figure this out for a while.  I have some code that looks like this:

PictureBox p = null;
PictureBox pb_dice = null;

for(int i = 1l I < 7; i++)
{
    p = this.Controls["p"  + i.ToString()] as PictureBox;
    pb_dice = this.Controls["p_dice" + i.ToString()] as PictureBox;
    p.Image = WindowsFormsApplication1.Properties.Resources.diceBlank;
    pb_dice.Image = WindowsFormsApplication1.Properties.Resources.diceBlank;
}

When I run it, I get an error "Object reference not set to an instance of an object."  for the pb_dice.Image, but the p.Image works fine.  The resource diceBlank.png is valid and I double-
checked that both Pictureboxes are indeed pictureboxes.  Both pictureboxes properties are identical and neither are part of a group or panel.

I'm using Visual Studio C# 2010 Express.
Any suggestions?



Answers (7)