Hello, I have this problem with multidimensional array on Form.
I have multidimensional array (like 5x5 matrix), but I can't add buttons on the form, if I use Controls.Add it adds only one button, and if i use Controls.AddRange program gives me an error
I want to make a logical game and multidimensional array is the key to my idea. This is the code I used, the commented lines are the ones that didn't work.
private void Form1_Load(object sender, EventArgs e)
{
Button[,] btnArr = new Button[5, 5];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
btnArr[i, j] = new Button();
btnArr[i, j].Size = new Size(75, 75);
btnArr[i, j].Text = "Button" + ((i + 1) * (j + 1));
//Controls.AddRange(btnArr[i,j]);
//btnArr[i, j].Controls.Add(Button);
}
}
}
Thanks for helping me :)
EDIT: I tried solving it with this code also
foreach (Button element in poljeButtona[Konstante.RETCI, Konstante.STUPCI])
Controls.Add(element);