Background color of TextBox control

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

Guest

I have windows form with the few TextBox controls.
Under certain conditions I disable or enable this controls by setting Enable
property to true or false: For example:

this.m_txtIP.Enabled = false ;

The controller become disabled, and I can't enter any data. The problem is
that the background color of the TextBox doesn't change whether it is enabled
or disabled.
It always looks like enabled.

Can anyone advise me what can prevent background of TextBox from changing
when I disable it? I didn't touch BackColor property of control and assumed
that
background of the control changes automatically, once Enable property is set
to false. Am I wrong?

Thanks
 
Steve said:
Can anyone advise me what can prevent background of TextBox from changing
when I disable it? I didn't touch BackColor property of control and assumed
that
background of the control changes automatically, once Enable property is set
to false. Am I wrong?

This assumption is probably wrong, although I haven't tried that myself.
I think the background color is determined by the BackColor property,
and most likely you have to change this when you change Enabled. It
would be nice to have a DisabledBackColor property, which would be used
*automatically* when the control is disabled.

You may want to try to write your own event handler that captures the
change of the Enabled property and updates the color accordingly.

Tom
 
Steve said:
I have windows form with the few TextBox controls.
Under certain conditions I disable or enable this controls by setting
Enable
property to true or false: For example:

this.m_txtIP.Enabled = false ;

The controller become disabled, and I can't enter any data. The problem is
that the background color of the TextBox doesn't change whether it is
enabled
or disabled.
It always looks like enabled.

Can anyone advise me what can prevent background of TextBox from changing
when I disable it? I didn't touch BackColor property of control and
assumed
that
background of the control changes automatically, once Enable property is
set
to false. Am I wrong?

Thanks
I tested this in a small C# Windows app here, and the background color in a
disabled text box does change automatically here, to the default form color.
Actually, the foreground color changes automatically as well, from a very
dark gray (normal text) to a medium gray. That said, I have no idea why your
behavior differs, unless you have loaded some sort of theme or customs color
template for Windows that is affecting your app? If you are running some
sort of theme, try removing it.
 
Steve said:
The controller become disabled, and I can't enter any data. The problem is
that the background color of the TextBox doesn't change whether it is enabled
or disabled.
It always looks like enabled.

I just verified it with VS2003 and 2005 Beta 2, and they both change the
background and font colors automatically when the text box gets
disabled. Not at design time, but at runtime certainly. Probably you
expected it to change at design time as well?

Tom
 
Back
Top