【发布时间】:2021-09-20 11:47:32
【问题描述】:
我已经使用两个for 循环创建了一个维度数组,并且随着每个内部循环的完成,我希望将这些值放入 Windows 窗体上的文本框中。 (我意识到每次都会覆盖这些值,最后只显示来自最终外部循环的值。)
代码中的 cmets 显示了我一直在努力工作的内容。
谢谢!
if (IsValidData())
{
int Columns = 5;
int Rows = Convert.ToInt32(txtNumbDrawings.Text);
int[,] ball = new int[Columns, Rows];
for (int i = 0; i < Rows; i++)
{
List<int> ballsList = new List<int>();
int[] txtBall = new int[Columns];
for (int j = 0; j < Columns; j++)
{
Random number = new Random();
ball[i, j] = number.Next(1, 70);
// prevent duplicate numbers
while (ballsList.Contains(ball[i, j] ))
{
ball[i, j] = number.Next(1, 70);
}
ballsList.Add(ball[i, j]);
/*************************************************
* how do I get the current ball value
* into a textbox on a form?
*
* textboxes are named txtBall1, txtBall2, etc...
*
* I was trying something like:
*
* TextBox[] txtBall = new TextBox[5];
* for (int i = 0; i < 5; i++)
* {
* txtBall[i + 1].Text = ball[i, j].ToString();
* }
*************************************************/
}
ballsList = null;
}
}
Windows Form Image: https://1drv.ms/u/s!Ak6hxvO3Ye6Oj5I9NQy834Yk4TRLyw?e=DniwK8
【问题讨论】:
-
你对这段代码有什么期望?
-
将每个
lstBall1放入一个数组并索引该数组。 -
有多少张图纸?