Board index » delphi » How to draw transparent text ?

How to draw transparent text ?

I'd like to draw transparent text on top of a (windowed) control. I find
that only label controls have the Transparent property, and they are
non-windowed controls, so they disappear behind any windowed control in a
form.

Does anyone know of any available text/edit controls that can be used to
draw transparent text on top of other windowed controls, or do you have
to use the API to accomplish this ? (If so, is that straightforward ?)

Grateful for (e-mailed) answers.

Anders Kroksaeter

 

Re:How to draw transparent text ?


Quote
Anders Kroksaeter (a...@veg.sintef.no) wrote:

: I'd like to draw transparent text on top of a (windowed) control. I find
: that only label controls have the Transparent property, and they are
: non-windowed controls, so they disappear behind any windowed control in a
: form.

: Does anyone know of any available text/edit controls that can be used to
: draw transparent text on top of other windowed controls, or do you have
: to use the API to accomplish this ? (If so, is that straightforward ?)

: Grateful for (e-mailed) answers.

: Anders Kroksaeter

In this situation I used TImage rather than a windowed control, so the
label is transparent and stays on top.  I didn't need the Timage to be
able to get the focus, so this worked for me.

--
Ray Hildreth  
Greater Columbus Free-Net
rh...@freenet.columbus.oh.us

Re:How to draw transparent text ?


Quote
Anders Kroksaeter <a...@veg.sintef.no> wrote:
> I'd like to draw transparent text on top of a (windowed) control. I find
> that only label controls have the Transparent property, and they are
> non-windowed controls, so they disappear behind any windowed control in a
> form.

> Does anyone know of any available text/edit controls that can be used to
> draw transparent text on top of other windowed controls, or do you have
> to use the API to accomplish this ? (If so, is that straightforward ?)

Using the API is pretty straight-forward, once you know how.  Basically, in
the Paint routine you'd do something like:

call inherited paint.
call SetBkMode(DC.handle, TRANSPARENT) saving the return value.
draw the text using one the API calls like TextOut, ExtTextOut, or DrawText.
Restore old background mode with the return value from above.

There is probably a way to set the background mode to transparent using the
VCL, but I don't have Delphi here to check.  I know that you can paint the
text itself using a member of the TDC object.

If you're really stuck, let me know and I can crank out something compilable
at home and post it for you.

Regards,
Brad
bstow...@pobox.com
Free Delphi Stuff:  http://www.pobox.com/~bstowers/delphi/

Re:How to draw transparent text ?


Quote
Anders Kroksaeter <a...@veg.sintef.no> wrote:
>I'd like to draw transparent text on top of a (windowed) control. I find
>that only label controls have the Transparent property, and they are
>non-windowed controls, so they disappear behind any windowed control in a
>form.

>Does anyone know of any available text/edit controls that can be used to
>draw transparent text on top of other windowed controls, or do you have
>to use the API to accomplish this ? (If so, is that straightforward ?)

        You can draw "transparent" text on a Canvas just by setting
Brush.Style:=bsClear first and then calling the canvas' TextOut method,
if that helps. (If you do this in an OnPaint event handler it gets redrawn
automatically.)

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...

Other Threads