how to handle a mass of lables in C#?
-
The problem is: I want to use a for control sentence to control 16 lables,each time I want to change one lable's Text property.Suppose the 16 lables are lable1,lable2,lable3,...,lable16. What does the code should look like?
-
The problem is: I want to use a for control sentence to control 16 lables,each time I want to change one lable's Text property.Suppose the 16 lables are lable1,lable2,lable3,...,lable16. What does the code should look like?
-
hi momor that will be for (i=1;i<=16;i++) { myLabel.Text = "Label" + i + "/n"; } that would help
Hi!Moustafa_, Thank you very much! But what I need is not to change one lable's Text property for 16 times,but to change 16 lable's Text properties.I want to realize it with a for loop,and change one lable's Text property in each loop.In this case,what should my code look like? Thank you again!
-
for(int i=0; i < this.Controls.Count; i++) if(this.Controls[i].GetType() == typeof(System.Windows.Forms.Label)) MessageBox.Show (this.Controls[i].Name);
-
Hi!hatim_ali, Thank you very much for your help! I think your code give me much idear to work out my trouble.;)
Hi!hatim_ali, The lable I want to get within each for loop is specified.That is,within the first loop I want to get lable1,within the second loop I want to get lable2,within the third loop I want to get lable3,...,within the 16th loop I want to get lable16.And there are more than 16 lables in my C# project,so if I use your code I don't know which lable I will get.I think maybe use a array or a enum which contains the 16 specified lables,but I just do not know what the array or enum's type should be and what the code look like. I need your help!;)
-
Hi!hatim_ali, The lable I want to get within each for loop is specified.That is,within the first loop I want to get lable1,within the second loop I want to get lable2,within the third loop I want to get lable3,...,within the 16th loop I want to get lable16.And there are more than 16 lables in my C# project,so if I use your code I don't know which lable I will get.I think maybe use a array or a enum which contains the 16 specified lables,but I just do not know what the array or enum's type should be and what the code look like. I need your help!;)
hi.... Enums Members[^] Arrays in C#[^] best of luck...