How to change all disabled controls backcolor

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to change the color used by windows to paint the backcolor of all
disabled controls in my application, because users, in certain conditions of
light, can't read the text.
I Think that I need to change something like SystemColors.GrayText, but it
seems to be readonly...
My application was developed using C# 2005.

Thank you
 
Try this:

foreach (Control c in this.Controls)
{
if(c.enabled == false)
c.BackColor = Color.Black;
}

-- Mikeq
 
Hi Mikeq,

If possible, I would prefer to change the backcolor used by windows to paint
disabled controls instead of iterating all controls and setting their
backcolor.

My application has many forms, so I'm afraid that if I had to code
everywhere a control enabled state can change (to enabled or disabled) my
source code will turn very heavy and error prone.

Is it possible to change the value of SystemColors.GrayText ? I know in
VS2005 it is readonly but maybe you can help me with some code to achieve
this result.

Thanks
 
Sorry Toze, I don't know how to do that. I would put the suggested code in
each form.Load() function. I underestand you have many forms, so I would also
define a global variable that represents the color that you want so that you
can change it in just one place.

Color myDisabledColor = Color.Whatever;
....
Form.Load()
{
foreach(Control c in this.Controls)
{
if(c.enabled == false)
c.BackColor = myDisabledColor;
}
}

-- Mikeq
 
Toze,

This is not possible. This is system wide setting and cannot be controlled
for one application only. As Mikeq said you can control this on per control.
 
Back
Top