Board index » cppbuilder » TEdit->Enabled=false and Font->Color problem

TEdit->Enabled=false and Font->Color problem

Hi, Tomasz!

To my mind it's correct behavior. How would your users understand that this
TEdit disabled if it has colors like enabled TEdit?

Quote
Tomasz Bech wrote:

> I'm doing these actions:

>    ((TEdit *)pcontrol)->Enabled=false;
>    ((TEdit *)pcontrol)->Color=clBtnFace;
>    ((TEdit *)pcontrol)->Font->Color=clWindowText;

> The background color is  changing, but font color isn't (i tried blue,
> red and so on) - it is still gray. It works fine when Enabled=true.
> I tried to add
>     ((TEdit *)pcontrol)->Invalidate();
>    ((TEdit *)pcontrol)->Update();
> but with no success.

> What's wrong??!?!

>         Tomasz Bech

--
| ))))) NCC
|
|___
|ooo|
|ooo|
|ooo|
|___|
Sergei.
 

Re:TEdit->Enabled=false and Font->Color problem


Tomasz,
When a component becomes disabled, it normally takes on the color assigned
by the user for windows that are disabled.  Typically, this is grey.  IOW,
it's a  "TEdit represent a Windows core component" problem, so you don't
have very much control over it beyond what's in the Object Inspector.
However, there are probably owner-draw solutions listed in this NG, so have
a look.

You will also find that TLabel components can't have clWindow as a color
(except perhaps if you write code to do it) - the designer will wipe out the
design-time assignment the next time you open the form in the designer.
Truly annoying.

Good luck!
Dave

Re:TEdit->Enabled=false and Font->Color problem


Hi Tomasz,

Quote
> The background color is  changing, but font color isn't (i tried blue,
> red and so on) - it is still gray. It works fine when Enabled=true.

Changing the Font of a TWinControl descendant eventually sends the control the
WM_SETFONT message.  It is Windows that does not allow the specification of Font
color when a control is explicitly disabled.  You can, however, place the Edit
on a container control (such as a TPanel), disable the Parent (Panel), then
change the font color.

Good luck!

--
Damon Chandler
http://bcbcaq.freeservers.com

Re:TEdit->Enabled=false and Font->Color problem


Hi, Tomasz!

The TEdit is just a wrapper around a standard Windows control, and I
believe what you are seeing is the standard behavior for that control.
There are a couple of things you can do. The simplest is to create a
TLabel the size of the TEdit, and with the font, etc. you want in the
"disabled" control. Then, when you disable the edit control, instead
make it invisible and replace it with the label. You can set the text in
the label caption to match that in the edit. Ideally, you can
encapsulate this in a custom component.

------
Mark Cashman (TeamB - C++ Builder), creator of The Temp{*word*203}Doorway at
http://www.temporaldoorway.com
- Original digital art, writing, music and more -
C++ Builder / JBuilder Tips and The C++ Builder Programmer's Webring
(Join us!)
http://www.temporaldoorway.com/programming/index.htm
------

Re:TEdit->Enabled=false and Font->Color problem


Perhaps change the colors BEFORE you disable the control?

Gambit

Quote
"Tomasz Bech" <tomasz.b...@bull.com.pl> wrote in message

news:38A18127.D34D657A@bull.com.pl...
Quote
> I'm doing these actions:

>    ((TEdit *)pcontrol)->Enabled=false;
>    ((TEdit *)pcontrol)->Color=clBtnFace;
>    ((TEdit *)pcontrol)->Font->Color=clWindowText;

> The background color is  changing, but font color isn't (i tried blue,
> red and so on) - it is still gray. It works fine when Enabled=true.

Re:TEdit->Enabled=false and Font->Color problem


Quote
Tomasz Bech wrote in message <38A18127.D34D6...@bull.com.pl>...
>I'm doing these actions:

>   ((TEdit *)pcontrol)->Enabled=false;
>   ((TEdit *)pcontrol)->Color=clBtnFace;
>   ((TEdit *)pcontrol)->Font->Color=clWindowText;

>The background color is  changing, but font color isn't (i tried blue,
>red and so on) - it is still gray. It works fine when Enabled=true.
>I tried to add

Windows automatically chooses the disabled font color. You can use the color
of your own liking by

1- calling SetSysColors. This is a bad hack. It changes the system color for
all controls in all programs. In my projects, I really don't care how my app
affects the appearance of other apps. That's what they get for being on the
same machine as my program.

2- Handle the painting of the control manually. To do this, derive from
TEdit and handle the painting messages.

3- Find a control that alread does #2 for you.

Harold Howe [Teamb]
http://www.bcbdev.com

Re:TEdit->Enabled=false and Font->Color problem


[rp]
Hi Tomasz,

Quote
> The background color is  changing, but font color isn't (i tried blue,
> red and so on) - it is still gray. It works fine when Enabled=true.

Changing the Font of a TWinControl descendant eventually sends the control the
WM_SETFONT message.  It is Windows that does not allow the specification of Font
color when a control is explicitly disabled.  You can, however, place the Edit
on a container control (such as a TPanel), disable the Parent (Panel), then
change the font color.

Good luck!

--
Damon Chandler
http://bcbcaq.freeservers.com

Other Threads