I don't want to repeat my code, so I want to make something that can change the text on multiple buttons. Is it any way you can specify what button is called and add that to the code for changing the text?
I know you can change text on a button with button1.Text = "X";
I have tried to make a string, so I only have to write the name of the button, so the calling code ends up being PickPlayer("button1");
.
My full code is:
private void button9_Click(object sender, EventArgs e)
{
pickPlayer("button9");
}
private void pickPlayer(string Button)
{
if (player % 2 == 0)
{
player += 1;
Button.Text = "O";
}
else
{
player += 1;
Button.Text = "X";
}
}
But it shows an error message as follows:
string does not contain a definition for Text.
What am I doing wrong?