help w/ using a var in a changing a property
Hey all,
Have a problem that is twisting my mind into a pretzel. I am wanting to use a int variable in a line of code inside a function. I am passing into the function which button to alter background image in the "box" variable. I really do not want to type out 20 lines of code for each button.
Here is the code snippet.
private void track(string turn, int box)
{
if (turn = "x")
{
this.btnPos[box].BackgroundImage = global::TicTacToe.Properties.Resources.x;
// Set boxes array position 1 to x
boxes[1] = "x";
// Change whos turn it is.
whosturn = "o";
this.plTurn.BackgroundImage = global::TicTacToe.Properties.Resources.o;
}
else
{
this.btnPos[box].BackgroundImage = global::TicTacToe.Properties.Resources.o;
// Set boxes array position 1 to x
boxes[1] = "o";
// Change whos turn it is.
whosturn = "x";
this.plTurn.BackgroundImage = global::TicTacToe.Properties.Resources.x;
When I debug the app, I keep getting "tictactoe.form1 does not contain a definition for btnPos"
There are definitions for btnPos1, btnPos2,.....btnPos9.
Main reason for wanting to have a function is that the teacher only gives an A if you compress the code functionality down as much as possible.
Any help or pointers would be appreciated.