Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / November 2007

Tip: Looking for answers? Try searching our database.

Finding all controls of a particular type.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David - 01 Nov 2007 19:27 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.