I have a form, and in design mode, I want to plunk down a bunch of custom
controls onto it, and set their properties. Then, when the application runs,
I want to do something to each of the custom controls.
What I actually have is a bunch of custom buttons for a machine control
panel. Each button is implemented as a custom control, an instance of the
MachineButton class. It has an OnOff property, with a boolean value. True =
0n, False = off. I want to do this without having to manually code a list
of MachineButtons, adding each new button created into it via code. To make
it work, I have to be able to find out what sort of control something is.
What I want to do is have a function that turns all the buttons off. The
pseudocode would look like this:
class MachineButton:control
{
//insert definition of MachineButton here. It's a custom control.
private bool varOnOff; //There's an OnOff property
public bool OnOff
{
get {return varOnOff;} set {varOnOff=value}
}
public void TurnOnAllTheButtons(bool newstate)
{
foreach (Control c in controls)
{ if (c is a MachineButton)
{ MachineButton mb=(MachineButton)c;
mb.OnOff=false;
}
}
}
Is there a way to write the (c is a MachineButton) test?
Kevin Spencer - 02 Nov 2007 11:16 GMT
if (c is MachineButton)...

Signature
HTH,
Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
>I have a form, and in design mode, I want to plunk down a bunch of custom
> controls onto it, and set their properties. Then, when the application
[quoted text clipped - 36 lines]
>
> Is there a way to write the (c is a MachineButton) test?
David - 02 Nov 2007 19:05 GMT
Awesome. I thought I was joking. All I had to do was take out the "a".
Thanks
> if (c is MachineButton)...
>
[quoted text clipped - 38 lines]
> >
> > Is there a way to write the (c is a MachineButton) test?