469,592 Members | 1,928 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

Background color of TextBox control

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

Nov 17 '05 #1
3 1810
Steve wrote:
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
Nov 17 '05 #2

"Steve" <St***@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
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.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 17 '05 #3

Steve wrote:
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
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by A.M | last post: by
2 posts views Thread by James Ramaley | last post: by
8 posts views Thread by Marco Pais | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.