We are supposed to code Conway's Game Of Life in a C# Winform application. So, I created a 10 by 10 "game board" out of buttons. Pink means dead, blue means alive. And for ease of access, each button is named after its coordinates on the game board (e.g. x1y1, x10y9, x5y5). But then I realized I have no idea how to loop through 100 form controls and perform do stuff to each individual according to their color/value. In HTML/Javascript, I used the following loop:
for(row = 1; row <= 10; row++){
board[row] = new Array(10); //creates a 10 by 10 matrix to store the board's values in it.
for(col = 1; col <= 10; col++){
var position = "x" + row + "y" + col;
var val = parseInt(document.board.elements[position].value);
board[row][col] = val;
}
}
So the question is this: Is there a way to call form controls through strings not variable names? Something like Form1.getControlByName(string)
or something?