Discussion:
Edit control with a colored border?
(too old to reply)
Woody
2011-06-19 07:41:34 UTC
Permalink
What is the easiest way to get an edit control (for an MFC dialog)
which as an interior border that can be turned on or off.

The effect is to show the edit box is "active" in some way (control
will not have focus). So when the border is off, it will look like a
normal edit control; when the border is on, user will see the text
within a colored box (inside the normal border of the edit control).
Nobody
2011-06-19 12:09:13 UTC
Permalink
Post by Woody
What is the easiest way to get an edit control (for an MFC dialog)
which as an interior border that can be turned on or off.
The effect is to show the edit box is "active" in some way (control
will not have focus). So when the border is off, it will look like a
normal edit control; when the border is on, user will see the text
within a colored box (inside the normal border of the edit control).
Are you talking about the background color? If so, see SetBkColor().
ScottMcP [MVP]
2011-06-19 16:05:17 UTC
Permalink
Post by Woody
What is the easiest way to get an edit control (for an MFC dialog)
which as an interior border that can be turned on or off.
The effect is to show the edit box is "active" in some way (control
will not have focus). So when the border is off, it will look like a
normal edit control; when the border is on, user will see the text
within a colored box (inside the normal border of the edit control).
It is not practical to put a border inside an edit control. You can
change the control's background color, or you can paint a border
outside the control, or you can put a CStatic under the control and
change its visibility on/off.
Woody
2011-06-19 17:39:38 UTC
Permalink
No, I didn't want to change the background color. The static control
would work if the border were around the edit control, but not within
it (I used this technique once). And, it depends on the painting
order, as the static would have to be painted first.

I suppose you'd have to use some kind of owner draw.
Joseph M. Newcomer
2011-06-19 20:18:50 UTC
Permalink
Painting order does not matter. If the painting order DOES matter, you have done
something else wrong.

You need to have the correct z-axis position (note that prior to the VS .NET versions, the
z-axis specified in the dialog editor was inverted from the correct z-axis), and you
really should have the WS_CLIPCHILDREN and WS_CLIPSIBLINGS styles set for your dialog. But
it does work, and I've done it, and drawing order, over which you have no control anyway,
doesn't matter.
joe
Post by Woody
No, I didn't want to change the background color. The static control
would work if the border were around the edit control, but not within
it (I used this technique once). And, it depends on the painting
order, as the static would have to be painted first.
I suppose you'd have to use some kind of owner draw.
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Woody
2011-06-27 07:41:46 UTC
Permalink
I found a way to accomplish this in a fairly straight-forward manner.
I used the background erase to generate the border, in WM_CTLCOLOR
handler. I created a bitmap of the correct size (74 x 20), and then a
brush from the bitmap. I passed this brush in the handler.

For demonstrating that it works, I hand-calculated the bitmap size,
but it could be done dynamically.

The only drawback with this method is that the border can only be 1
pixel wide to maintain separation from the text background. I'm using
a normal edit control, not rich edit, in which I would have more
control over the margins.

Joseph M. Newcomer
2011-06-19 20:16:33 UTC
Permalink
I have tried doing things like this, and it is very difficult; edit controls have their
own notion of reality, and trying to do something else with it will be doomed.

What I ended up doing (and what worked) was putting a static control, owner-drawn, around
the edit control, and drawing it as either entirely in the dialog color (COLOR_3DFACE) or
in the desired highlight color (I was using red to indicate required fields that were not
filled in, for example).

In my validating edit control, I used background color to indicate completeness of a
value; even managing background color took a lot of work to force the edit control to
cooperate.
joe
Post by Woody
What is the easiest way to get an edit control (for an MFC dialog)
which as an interior border that can be turned on or off.
The effect is to show the edit box is "active" in some way (control
will not have focus). So when the border is off, it will look like a
normal edit control; when the border is on, user will see the text
within a colored box (inside the normal border of the edit control).
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Loading...