Hi guys, new to the forum :)
I have a c# program that consists of only one form, and am looking for a way of retrieving an array or list of all the picture boxes in that form.
I am not really new to c# but have only increased my knowledge so far as to accommodate assignment work requirements, i have not 'learnt' the language per se.
I blundered in and attempted to use this.componants only to find that, visual studio (which is what i am using) informed me there was no object reference in that statement, by which i assume it means the form, but i'm obviously not sure ;)
Ideally it would be some form of 'foreach' however i would appreciate guidance onto any method :D
Anyone have any ideas how i would go about doing this? Or is it even possible?
Thankyou.
Loading

Subhendu DeRank #1,108 · 1.7K reputationPosted Dec 14, 2010, 7:02 AM EST
Thanks.....
Sam M5 reputationPosted Dec 14, 2010, 8:44 AM EST
Ah of course, sorry, i normally post on HTML forums so wasn't sure of what would be useful regarding c# :)
Its just a basic tic-tac-toe game, all that is in the form is 9 picture boxes the r1l = row1left and r1c = row1center etc :) they represent the 9 squares (made by the picture boxes) that make up the tic-tac-toe.
Basically, on the click of the btnReset i would like it to retrieve all the picture boxes and put them into a list or array.
Its not hugely important to the functionality, but i'm mainly making this program to improve my knowledge of deeper c# concepts :D
Cheers :)
CrishRank #1,487 · 1.1K reputationPosted Dec 14, 2010, 11:14 PM EST
you can check this below code to solve your issue.
http://www.xtremevbtalk.com/showthread.php?t=143177
Sam M5 reputationPosted Dec 14, 2010, 11:29 PM EST
However, unless I am being stupid, that code appears to be in VB ;)
Any chance you have a c# example?
Thanks :D
FroglegRank #1,020 · 1.9K reputationPosted Dec 15, 2010, 10:50 AM EST
PictureBox[] pic = new PictureBox[9];
put "setupPics();" in form load event
public void setupPics()
{
pic[0] = pictureBox1;
pic[1] = pictureBox2;
pic[2] = pictureBox3;
pic[3] = pictureBox4;
pic[4] = pictureBox5;
pic[5] = pictureBox6;
pic[6] = pictureBox7;
pic[7] = pictureBox8;
pic[8]= pictureBox9;
}
private void button2_Click(object sender, EventArgs e)
{
foreach (PictureBox p in pic)
{
p.Image = null;
}
}
Sam HobbsRank #107 · 20.5K reputationPosted Dec 15, 2010, 6:47 PM EST