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
Tamas Demjen - 05 May 2005 18:02 GMT
> 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
Peter van der Goes - 06 May 2005 13:05 GMT
>I have windows form with the few TextBox controls.
> Under certain conditions I disable or enable this controls by setting
[quoted text clipped - 18 lines]
>
> 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.

Signature
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Tamas Demjen - 06 May 2005 17:51 GMT
> 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