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
Jignesh TrivediPosted Mar 19, 2012, 3:52 AM
yes you must cast your object to custom object other wise you can not get that property.
above code is good but try ...
foreach (Control c in this.Controls)
{
var cc= c as CustomControl;
if(cc !=null)
{
cc.FocusColour = Color.Yellow;
}
}
hopet his help.
Walter KiessPosted Mar 19, 2012, 1:28 AM
I have received a reply from another website which has provided a solution:
foreach (Control c in this.Controls)
{
if (c is CustomControl) ((CustomControl)c).FocusColour = Color.Yellow;
}
HTH Someone else...
Walter