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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Scott LyslePosted May 26, 2008, 9:29 PM
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;
}
}