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
Sam HobbsPosted Dec 15, 2010, 11:47 PM
FroglegPosted Dec 15, 2010, 3:50 PM
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 MPosted Dec 15, 2010, 4:29 AM
However, unless I am being stupid, that code appears to be in VB ;)
Any chance you have a c# example?
Thanks :D
CrishPosted Dec 15, 2010, 4:14 AM
you can check this below code to solve your issue.
http://www.xtremevbtalk.com/showthread.php?t=143177
Sam MPosted Dec 14, 2010, 1:44 PM
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 :)
Subhendu DePosted Dec 14, 2010, 12:02 PM
Thanks.....