I'm not sure how to describe this in the title, so it may be misleading.
Basically, I want to change the image of a LOT of buttons. And when I say a lot, I mean 93 of them.
So obviously, this approach:
btnSinglePlay.BackgroundImage = Image.FromFile(buttonN);
would take too long, since I have to repeat it for every button, and could be prone to errors.
Researching on the internet gave me this code:
this.pnlBoard.Controls[buttonName].BackgroundImage = Image.FromFile(pieceName);
where I believe I can simply change the (string) buttonName via a for loop, saving me from doing it 93 times EVERY time I need the buttons to change images.
Notice that this code only allows me to change BACKGROUND image, and not IMAGE, for reasons I don't know.
However, executing that code gets me the following error:
NullReferenceException was unhandled.
Object reference not set to instance of an object.
I have no idea what this means. Presumably there has to be a " = new Control() " somewhere in there, but I don't know where / how.
Any ideas on this?
Also, is there any other similar way / code that would allow me to change the images of a button, without have to go through them one by one?
Thanks in advanced.