C#groupBox lotto,需要帮助为组框分配变量

时间:2017-11-04 10:52:05

标签: c# variables groupbox

Category.objects.get(category = "abc")
I get this error:

DoesNotExist: Category matching query does not exist.

您好, 在上面的代码片段中,我想将Line1更改为字符串变量,但我不确定这样做的正确语法。有人可以帮忙解决这个问题吗?这是C#

Line1是GrouBox名称。 我希望能够将Line1更改为字符串。像这样:

        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];
        }

    }

代码无效但

1 个答案:

答案 0 :(得分:0)

您可以像这样使用表格Controls的{​​{1}}数组......

this.Controls

...就像您从string groupBoxName = "Line1"; Control groupBox = this.Controls[groupBoxName]; groupBox.Controls[nb].BackgroundImage = CircleColours[i]; 的{​​{1}}数组中动态获取NumberBox一样。