Good day. One of the buttons has an event (creating an array of queues, the number of elements in which is output to the labels), which includes the following code block:
{ Random rnd = new Random(); M = int.Parse(textBox1.Text); //Количество очередей QArray = new Queue<int>[M]; int [] Array = new int[30]; for (int i = 0; i < 30; i++) { Array[i] = i + 1; } int ArrayCount = 30; int MaximumValue; int element; for (int i = 0; i < M; i++) { { MaximumValue = 0; QArray[i] = new Queue<int>(); int count = rnd.Next(1, 8); //Количество элементов в очереди for (int j = 0; j < count; j++) { if (ArrayCount > 0) { if (MaximumValue == 30) break; element = rnd.Next(0, 30); do { element = rnd.Next(0, 30); if (Array[element] < MaximumValue) continue; } while (Array[element] == 0); MaximumValue = Array[element]; Array[element] = 0; QArray[i].Enqueue(Array[element]); ArrayCount--; } } } if (MaximumValue > MaximumofM) MaximumofM = MaximumValue; labelArray = new Label[M]; labelArray[i] = new Label(); labelArray[i].Location = new Point(30 + 40 * i, 100); labelArray[i].Text = QArray[i].Count.ToString(); labelArray[i].Size = new Size(25, 15); this.Controls.Add(labelArray[i]); } } By pressing another button in one of the array queues, an element is added, so the value on the labels should change. The code below would have to remove all labels, but they do not change. Tell me how to change the values in the labels now? Thank you in advance
int add=rnd.Next(0, M+1); QArray[add].Enqueue(MaximumofM); for (int i=0;i< M; i++) { labelArray[i] = new Label(); labelArray[i].Text = QArray[i].Count.ToString(); //Количество элементов в очереди labelArray[i].Location = new Point(30 + 40 * i, 100); labelArray[i].Size = new Size(25, 15); }
labelArray[i] = new Label();- remove this line from the second code fragment - Igor