Assiging name to label dynamic way ???
-
I made a Windows form in C# which contains 2 labels and 2 text fields the label name are saved in xml the xml fomat is
and u know to change the name of label we write label01.Text=string1; label02.Text=string2; I do not want to use this. in case I have many labels then?? My question is there any other way so that i change its text (geting label01 from xml and its respective text).throug loping crateria. thanks in advance..... Sikandar
sikandar
-
I made a Windows form in C# which contains 2 labels and 2 text fields the label name are saved in xml the xml fomat is
and u know to change the name of label we write label01.Text=string1; label02.Text=string2; I do not want to use this. in case I have many labels then?? My question is there any other way so that i change its text (geting label01 from xml and its respective text).throug loping crateria. thanks in advance..... Sikandar
sikandar
You can iterate over the controls collection looking for labels if you prefer, and if that works with the data you need to place into the labels. You could even iterate over the controls collection and create a new collection of only labels, but as soon as a label is added or removed, this would be wrong ( unless you made a private property that did this every time you wanted the labels collection ).
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
I made a Windows form in C# which contains 2 labels and 2 text fields the label name are saved in xml the xml fomat is
and u know to change the name of label we write label01.Text=string1; label02.Text=string2; I do not want to use this. in case I have many labels then?? My question is there any other way so that i change its text (geting label01 from xml and its respective text).throug loping crateria. thanks in advance..... Sikandar
sikandar
Hello My friend! Your request was not in definite. May be below code can help you :
int i=1; foreach (Control ctrl In this.Controls) { if (ctrl Is Label) { ctrl.Text = "Label" + i.ToString(); i++; } }
please contact me if i couldn't help you. -
Hello My friend! Your request was not in definite. May be below code can help you :
int i=1; foreach (Control ctrl In this.Controls) { if (ctrl Is Label) { ctrl.Text = "Label" + i.ToString(); i++; } }
please contact me if i couldn't help you.done thanks
sikandar