我正在尝试更改已单击按钮的属性。根据点击的按钮,我无法弄清楚如何做到这一点。我不想为每个按钮复制方法。
这是我的代码:
private void GetPlayerChoice_Click(object sender, EventArgs e)
{
if (playerX.Turn == true)
{
button1.Text = playerX.Name;
button1.BackColor = Color.FromArgb(255, 15, 0);
playerX.Turn = false;
playerO.Turn = true;
}
if (playerO.Turn == true)
{
button1.Text = playerO.Name;
button1.BackColor = Color.FromArgb(96, 255, 40);
playerX.Turn = true;
playerO.Turn = false;
}
}
答案 0 :(得分:1)
你在eventhandler的sender参数中有你的按钮。 所以你可以尝试:
Button button = sender as Button;
if (button != null)
{
button.Text = "Clicked";
}