How can i find out how many objects are on a form? want to loop through the objects and find the textbox and be able to enable or disable..... using C#.net 3.5
Thanks
How can i find out how many objects are on a form? want to loop through the objects and find the textbox and be able to enable or disable..... using C#.net 3.5
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Scott LysleRank #49 · 31K reputationPosted May 26, 2008, 5:29 PM EDT
Use the controls collection for the form; for example, with five textboxes, this will set all of the text properties to "Ziglofrock", then will find the textbox named textBox3 and set its text property to "Bagette", and then it will find the textbox named textBox4 and disable it.
foreach (Control c in this.Controls)
{
if (c.GetType().ToString() == "System.Windows.Forms.TextBox")
{
((System.Windows.Forms.TextBox)(c)).Text = "Ziglofrock";
if(((System.Windows.Forms.TextBox)(c)).Name == "textBox3")
((System.Windows.Forms.TextBox)(c)).Text = "Bagette";
if (((System.Windows.Forms.TextBox)(c)).Name == "textBox4")
((System.Windows.Forms.TextBox)(c)).Enabled = false;
}
}