S
Stefan W via .NET 247
I'm relatively new to C#, (I have to use it, now that I'veinherited someone else's projects). I'm looking for a way toiterate through the controls on a form; if the control is of acertain type, I want to set a property that is specific to thatcontrol type. The problem I'm having is that the "generic"Control object might not
contain the properties that I want to set.
Here's an example of what I'd like to try to do:
//loop through all controls on a form
foreach(Control ctrl in this.Controls)
{
//if control is a textbox
if(ctrl is TextBox)
{
//set a property that is specific to that control type
//If ctrl is a Textbox, set the ReadOnly property to True
ctrl.ReadOnly = true;
}
}
That is the general idea that I have; unfortunately, I'm notcertain that it's
possible to do this. Any help would be appreciated.
Thanks!
contain the properties that I want to set.
Here's an example of what I'd like to try to do:
//loop through all controls on a form
foreach(Control ctrl in this.Controls)
{
//if control is a textbox
if(ctrl is TextBox)
{
//set a property that is specific to that control type
//If ctrl is a Textbox, set the ReadOnly property to True
ctrl.ReadOnly = true;
}
}
That is the general idea that I have; unfortunately, I'm notcertain that it's
possible to do this. Any help would be appreciated.
Thanks!