Hello -
on my noughts and crosses / tic tac toe game I have initialised a 3 x 3 array and addded buttons using all the code below. If I want to also have a 5X5 array game and aa 7X7 array game - how do I go about it without repeating all the button code ? I know that I obviously change 3X3 for 5X5 and 7X7 but after that I 'm getting a bit stuck:-/
thank you for any ideas .... all the best John
private void Form1_Load(object sender, EventArgs e)
{
for (int x = 0; x < 3; x++)//loop relating to rows
{
for (int y = 0; y < 3; y++)//loop relating to columns
{
nandcButton[x, y] = new Button();//Create the Buttons
nandcButton[x,y].Name = "nandcButton" + x + ","+ y;//name and coordinates and set up number, number to show
nandcButton[x,y].Width = 60;
nandcButton[x,y].Height = 60;
nandcButton[x,y].Left = nandcButton[x,y].Left + nandcButton[x,y].Width + (x * 60);
nandcButton[x,y].Top = nandcButton[x,y].Top + nandcButton[x,y].Top + 50 + (y * 60); //Centre the button
nandcButton[x,y].Click += new EventHandler(Button_Click); //links the above button spec.
//Add them to the container
nandcHolder.Controls.Add(nandcButton[x,y]);
nandcButton[x, y].Text =" "; //declares text
}
}
}