Walter Kiess

Walter Kiess

  • NA
  • 53
  • 12.7k

C# - How to iterate a form's custom controls

Mar 19 2012 12:22 AM
Hi C# Gurus, 

I have created my own custom Textbox control which I intend to use on every form in my application rather than the standard Textbox control. 
One of the things I do when the app starts is to call a common routine/method/procedure (call it what you will) which iterates thru all the controls on the form, settings it's colours according to the user selected colour scheme. This all works fine for the standard window's controls, but not for the custom control's new property: FocusColour. I'm using a pretty standard loop to iterate thru the controls:
 foreach(Control c in f.Controls){} 
When it hits the custom textbox control, setting the Back and ForeColor properties works fine, but I can't set the new FocusColour property because it doesn't appear in intellisense and the program won't run (shows errors) if I manually type the property i.e. 
c.FocusColour = Colors.Yellow;
My question is: How can I iterate thru all the custom controls on the form to set the new properties, or how can I include the custom properties once a custom control is found in the above loop? 

Thanks in advance, 
Walter

Answers (2)