这本应在xWinner表单标签中显示获胜者,但我无法弄清楚。
xWinnerForm.Show(b1.Text);。我是C#的新手,所以可以请外行解释一下。谢谢。
static public bool CheckWinner(Button[] myControls)
{
bool gameOver = false;
for (int i = 0; i < 8; i++)
{
int a = Winners[i, 0];
int b = Winners[i, 1];
int c = Winners[i, 2];
Button b1 = myControls[a], b2 = myControls[b], b3 = myControls[c];
if (b1.Text == "" || b2.Text == "" || b3.Text == "")
continue;
if (b1.Text == b2.Text && b2.Text == b3.Text)
{
gameOver = true;
Form xWinnerForm = new xWinnerForm();
xWinnerForm.Show(b1.Text);
}
public void Show(string text)
{
this.xWinnerLabel.Text = text;
this.Show();
}
}
return gameOver;
}
最佳答案
这是使其生效所需的最小更改:
xWinnerForm xWinnerForm = new xWinnerForm();
尽管我建议除此以外进行一些更改:
使用PascalCase作为类名,但不要使用驼峰大小写作为变量名。
XWinnerForm xWinnerForm = new XWinnerForm();
不要以这种方式重载
Show
。而是更改表单的构造函数以接受额外的数据,或者向表单添加setter。XWinnerForm xWinnerForm = new XWinnerForm(b1.Text);
请勿使用
a, b, c, b1
之类的名称:XWinnerForm xWinnerForm = new XWinnerForm(labelWinner.Text);
关于c# - 无法从字符串转换为system.windows.forms.string iwin32window,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2897206/