[英]C# groupBox lotto, need help assigning variable for group box
private void LineUpNumbers ()
{
Array.Sort(lineArray[currentSelectedLine]); // Sorts the array in ascending order.
string numberBox = "Line" + (currentSelectedLine + 1).ToString() + "NumberBox";
string nb;
Image[] CircleColours = new Image[6] {Properties.Resources.BlueCircle, Properties.Resources.RedCircle , Properties.Resources.OrangeCircle , Properties.Resources.PurpleCircle , Properties.Resources.GreenCircle , Properties.Resources.YellowCircle};
Random r = new Random();
CircleColours = CircleColours.OrderBy(x => r.Next()).ToArray();
for (int i = 0; i <6; i++) // Populates NumberBoxes with the numbers from the array
{
nb = numberBox + (i + 1);
Line1.Controls[nb].Text = lineArray[currentSelectedLine][i].ToString();
Line1.Controls[nb].BackgroundImage = CircleColours[i];
}
}
嗨,在上面的代码片段中,我想将Line1更改为字符串变量,但是我不确定这样做的正确语法。 有人可以提供解决方案吗? 这是C#
Line1是GrouBox名称。 我希望能够将Line1更改为字符串。 像这样:
string groupBoxName = "Line1";
groupBoxName.buttonName.BackgroundImage = CircleColours[i];
该代码虽然不起作用
您可以使用Form this.Controls
数组的Controls
数组...
string groupBoxName = "Line1";
Control groupBox = this.Controls[groupBoxName];
groupBox.Controls[nb].BackgroundImage = CircleColours[i];
...就像从GroupBox
的Controls
数组动态获取NumberBox
的方式一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.