How to change all disabled controls backcolor

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
 
G

Guest

Try this:

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

-- Mikeq
 
G

Guest

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
 
G

Guest

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
 
S

Stoitcho Goutsev \(100\)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top