【问题标题】:Button array For tic tac toe Assignment [duplicate]用于tic tac toe分配的按钮数组[重复]
【发布时间】:2021-12-17 15:33:00
【问题描述】:

我有一个任务,我应该通过这个任务创建一个名为“tic tac toe”的游戏。 在这个任务中,w 被要求创建类似的东西;

私人按钮 [,] ticTacToeButtons

我不知道如何使用它。我使用 Windows 表单应用程序创建了 9 个按钮,并在后台尝试将此按钮与此数组连接,但我不确定哪些元素可以添加到此数组中。

【问题讨论】:

  • 您需要将按钮控件添加到该数组中

标签: c# arrays button tic-tac-toe


【解决方案1】:

创建一个按钮数组

static void Main(string[] args)
{

    Button[] buttons = new Button[10];
    for(int i = 1; i < 10; i++)
    {
       buttons[i] = new Button();
       buttons[i].Text = "";
       Controls.Add(buttons[i]);
    }
}

【讨论】:

  • 我学会了。希望这个回答对大家有所帮助;
  • public Form1() { InitializeComponent(); ticTacToeButtons = new Button[3, 3] { { this.button1, this.button2, this.button3 }, { this.button4, this.button5, this.button6 }, { this.button7, this.button8, this.button9 } } ; } private Button[,] ticTacToeButtons;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-23
  • 2014-01-23
  • 2018-09-03
  • 1970-01-01
相关资源
最近更新 更多