有没有办法在 C# 中使用数值来引用按钮?我正在尝试使用一种可重用的方法来操作按钮上的文本。下面是我目前的编码: 一键点击方式(一共16个):
private void Card1_Click(object sender, EventArgs e)
{
buff = CardClick(1);
if (buff != null)
{
Card1.Text = buff;
}
}
以及可重用的方法(代码确实有漏洞,正在开发中):
private string CardClick(int card)
{
guesses[g++] = card; //alternate g
if ((guesses[0] != null) && (guesses[1] != null))
{
//Reset Card guesses[0]
//Reset Card guesses[1]
return null;
}
else
{
if (card > 8)
{
return map[2, card];
}
else
{
return map[1, card];
}
}