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:
Code
foreach(Control c in f.Controls){}Code
c.FocusColour = Colors.Yellow;Thanks in advance,
Walter

Walter Kiess24 reputationPosted Mar 18, 2012, 9:28 PM EDT
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
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 18, 2012, 11:52 PM EDT
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.