CyberPirate1
1
Newbie Poster
Recommended Answers
Jump to PostThis will loop through all of the form's controls searching for the name of the control....
private void button2_Click(object sender, EventArgs e) { for (int i = 1; i <= 3; i++) foreach (Control c in this.Controls) if (c.Name == "label" + i) c.Visible = true; }
Jump to PostNo problem. The foreach loop is iterating through the form's control list, which is maintained by the designer every time you add or remove controls to/from your form. Then, we are checking the name of the control (c.Name) to find the labels: label1 - label3, based on what you said …
All 6 Replies
DdoubleD
315
Posting Shark
CyberPirate1
1
Newbie Poster
Geekitygeek
commented:
exactly the kind of attitude i like to see, if something confuses you, ALWAYS ask :)
+1
DdoubleD
315
Posting Shark
Geekitygeek
commented:
a good answer and a clear explaination :)
+1
DdoubleD
315
Posting Shark
CyberPirate1
1
Newbie Poster
Geekitygeek
480
Nearly a Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.