【发布时间】:2016-05-22 02:58:11
【问题描述】:
我正在寻找在按钮上显示二维值数组的优化代码。 我创建了这样的按钮网格: http://screenshot.sh/m2eZscO4i0fXq 我实际上正在使用此代码在此按钮上显示数组值:
button1.Text = board.gameBoard[0, 0].getValue().ToString();
button2.Text = board.gameBoard[0, 1].getValue().ToString();
button3.Text = board.gameBoard[0, 2].getValue().ToString();
button4.Text = board.gameBoard[0, 3].getValue().ToString();
button5.Text = board.gameBoard[1, 0].getValue().ToString();
...
button15.Text = board.gameBoard[3, 2].getValue().ToString();
button16.Text = board.gameBoard[3, 3].getValue().ToString();
有更简单的方法吗?它现在正在工作(http://screenshot.sh/mMDP9pvcC7WOk),但我认为这不是做这件事的最佳方式。有人可以告诉我如何做得更好吗?
【问题讨论】:
-
您可能会发现这篇文章很有用:How to create a magic square using Windows Forms?
-
是的,这很棒。我看的时间不够长 :D 这比我认为的下面的解决方案更好。我说的对吗?