
Change background color of disabled CEdit controls
Quote:
> Can someone tell me if there is a way to change the background and character
> collor of a disabled CEdit control. (The gray characters on a gray
> background are not always readable) I look rather to change the property of
> the CEdit control than getting a DC for every control and repainting my
> controls.
Well, yes and no. The appearance of something like a disabled edit box is system defined. This
allows the user to use a desktop themes package (like the one in Microsoft Plus!) to define how each
visual element should look on their system. Your application is then supposed to use these system
defined colors.
You can use the OnCtlColor() event to tell the OS to use different colors for a specific window, but
for a disabled edit box the OS will ignore the text color you return and use the system color
COLOR_GRAYTEXT instead. It will use the background and text background colors though, so you could
lighten the background instead of darkening the text to get a better contrast.
However, this is a system incompatible hack and you really should stick with whatever colors the
user has defined for the system to stay compatible with the OS accessibility features. For some
visually impaired folks, like me, the font colors, types, and sizes we choose for the system are
very important to our ability to use the applications effectively.
The disabled flag is intended to be used for an edit box that should not be selected, read, or
written. If what you actually want is to just disable the write or edit ability, but allow the user
to read, select, or copy the contents, then what you want to use is the SetReadOnly() method which
sets the ES_READONLY flag on the edit box. This will still gray the background, but it will use the
normal text color and the user can select and copy the contents.
There are some application developers that do not like the gray background of the readonly edit box.
What they do is to use the OnCtlColor() event to change the color of any readonly edit box in their
application to a normal window background (COLOR_WINDOW) and the disabled color for the text
(COLOR_GRAYTEXT). This creates less of a visual discontinuity when the edit box changes state but
still clearly indicates the current state.
--
The Snake Pit - Development
Proprietor