markBegin2Code
New member
- Joined
- Mar 2, 2021
- Messages
- 4
- Programming Experience
- Beginner
Hi
I have a Windows form with some labels on that I want to populate into a Labels array. Putting them into the Array is no problem, but if I have a lot of Labels, or if the number of labels I have changes dynamically I want to populate the labels into an Array with a for loop.
I have created 6 labels on my form (lblNumber1, lblNumber2, lblNumber3, lblNumber4, lblNumber5, lblNumber6)
so I create an Array to work with 6 labels for now
then I create the for loop
When I run simple Text update, the label does not update?
on the for loop I put a message box
and I can see the Label Names look like they are going correctly in the Array?
Any ideas?
Thanks
I have a Windows form with some labels on that I want to populate into a Labels array. Putting them into the Array is no problem, but if I have a lot of Labels, or if the number of labels I have changes dynamically I want to populate the labels into an Array with a for loop.
I have created 6 labels on my form (lblNumber1, lblNumber2, lblNumber3, lblNumber4, lblNumber5, lblNumber6)
so I create an Array to work with 6 labels for now
C#:
Label [] lotNumbers = new Label[6];
C#:
for(int i = 0; i < 6; i++)
{
lotNumbers[i] = new Label();
lotNumbers[i].Name = "lblNumber" + (i + 1);
this.Controls.Add(lotNumbers);
}
C#:
lotNumbers[3].Text = "Hello World";
lotNumbers[3].Update();
C#:
MessageBox.Show(lotNumbers.Name.ToString());
Any ideas?
Thanks
Last edited by a moderator: