gpt4 book ai didi

c# - 无法从字符串转换为 system.windows.forms.string iwin32window

转载 作者:太空宇宙 更新时间:2023-11-03 16:53:58 24 4
gpt4 key购买 nike

这应该在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com