Question about .net 2.0 and C#:
In the open event of my WinForms I do a loop trough all the controls
collection.
I have inherited new controls from the base controls (button, label, .), all
with a new property (security).
Now, I have modified the loop in the open event to check if the control has
the property set to true.
I have used this code:
private void loopControls(Control.ControlCollection ctrls)
{
foreach(Control ctr in ctrls)
{
loopControls (ctr.Controls);
if (ctr.GetType() == typeof(customButton))
{
if (((customButton)ctr).Security == true)
{
// Make something
}
}
}
}
The problem is that now I have 4 or more customControls and I have to check
in the if the type for all the diferent controls.
¿Is there a way to do it more elegant?
I have tried to inherite all my controls from an interface and chek if the
control implment the interface, but dosen't work (a interface can't have a
property). Note: All the custom control unherit from base controls.
A lot of thanks.
Alex B.