This fragment is about to be reported (you'll remain on this page):

You can enter a comment to clarify the mistake if you would like to:

RichEdit with transparent background in Delphi? Hell yes!

Is IS possible to create a TRichEdit control with transparent background in Delphi.

RichEdit with transparent background in Delphi? Hell yes!

Yesterday I've stumbled upon an interesting demo of a transparent RichEdit control made for VisualC++ at The Code Project (called «See through Rich Edit control»). I'm currently writing an app in Delph 7 which uses TRichEdit as a log/console window and looking at that demo with cute Mario face I thought how cool would it make plain console window look like that too.

I went digging and discovered that to create a transparent RichEdit you simply and merely need to create its window with WS_EX_TRANSPARENT style – and also supply an WM_ERASEBKGND handler to make sure no junk is left from previous redraws.
Adding a custom style seemed a trivial task in Delphi – simply override TWinControl'sCreateParams method and add your style to ExStyle. However, this didn't work out for some reason (the control was behaving like it known nothing of WS_EX_TRANSPARENT)) but resorting to this method:

pascalprocedure TTransparentRichEdit.CreateWnd;
begin
  inherited;
  SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TRANSPARENT);
end;

…fixed that.

Hurray, now we only need to hook WM_ERASEBKGND – no surprises here so you can proceed to downloading the component without furner ado from my side :)

Download TTransparentRichEdit control (it has no external dependencies).

If you haven't installed any custom component yet simply go to Component → Install component menu. Note that this class was written and tested on Delphi of 7th version only.

http://proger.i-forge.net/Мои проги/Delphi/Transparent RichEdit/index.png

Usage notes

  • albeit you can do tricks with PNG transparency (if you have TPNGObject registered as Delphi's TGraphic) and underlying components (like on the screenshot) but be aware that it's unstable – read the note.
  • setting Align property makes the control flicker heavily when resizing its container and DoubleBuffering doesn't seem to help much too.

What you see here is actually a TTransparentRichEdit control with Nagato’s portrait PNG loaded (the Background property), below which lies a standard TImage with a JPEG picture shining through the RichEdit’s background.

However, use such tricks with overlaying controls on your risk because it might result in glitches – for example, TImage seems to be painted after the RichEdit receives WM_ERASEBKGND and thus it fully overlays the latter when window is resized.
It works fine when there’s nothing below RichEdit, though.

Comments RSS20

Your name: Your homepage:

Text & signature markup:You can use UverseWiki markup. In short: **bold**, //italic//, %%code%%, ((URL link)), >inline quote, <[ multiline quote ]>.

Humans! Please enter "J" here: (or turn JavaScript on for automatic verification)
Subscribe by e-mail (manage):
Ctrl+Enter »

Avatar

14 March 2013

When I edit the text in the Richedit and have a background image either a image behind the richedit or a background image from the components property, the text gets scrambled and overlaps. Any way to fix this behavior? I have a onchange event, what could I use in this event to prevent overlapping text?

Your name: Your homepage:

Text & signature markup:You can use UverseWiki markup. In short: **bold**, //italic//, %%code%%, ((URL link)), >inline quote, <[ multiline quote ]>.

Humans! Please enter "J" here: (or turn JavaScript on for automatic verification)
Subscribe by e-mail (manage):
Ctrl+Enter »
Avatar

14 March 2013

Homepage Follow thread #3.1

Proger_XP

If I understand your problem this happens because RichEdit no more has any background and thus can’t clear itself and when it’s repainted old bits are left and new view is painted over them. The result is garbage. I haven’t looked into this much but as I understand it’s a fundamental problem, you’ll have to either have a normal background for RichEdit to erase with or clear its old canvas yourself some other way on WM_ERASEBKGND.

Your name: Your homepage:

Text & signature markup:You can use UverseWiki markup. In short: **bold**, //italic//, %%code%%, ((URL link)), >inline quote, <[ multiline quote ]>.

Humans! Please enter "J" here: (or turn JavaScript on for automatic verification)
Subscribe by e-mail (manage):
Ctrl+Enter »
Avatar

15 December 2012

Follow thread #2

Anonymous

Hi, this is very nice but I can’t do the same thing with TMemo or TEdit. any idea?

Your name: Your homepage:

Text & signature markup:You can use UverseWiki markup. In short: **bold**, //italic//, %%code%%, ((URL link)), >inline quote, <[ multiline quote ]>.

Humans! Please enter "J" here: (or turn JavaScript on for automatic verification)
Subscribe by e-mail (manage):
Ctrl+Enter »
Avatar

15 December 2012

Homepage Follow thread #2.1

Proger_XP

I’ve checked it but looks like this trick won’t work and I couldn’t find a quick way of making it so. Although TRichEdit inherits from TCustomMemo either Windows treats this control differently or there’s something else in VCL processing background that TRichEdit disables.

Your name: Your homepage:

Text & signature markup:You can use UverseWiki markup. In short: **bold**, //italic//, %%code%%, ((URL link)), >inline quote, <[ multiline quote ]>.

Humans! Please enter "J" here: (or turn JavaScript on for automatic verification)
Subscribe by e-mail (manage):
Ctrl+Enter »
Avatar

21 August 2012

Follow thread #1

gian55

works great on DELPHI 2010… I've just compiled with success!!! thank to the author

Your name: Your homepage:

Text & signature markup:You can use UverseWiki markup. In short: **bold**, //italic//, %%code%%, ((URL link)), >inline quote, <[ multiline quote ]>.

Humans! Please enter "J" here: (or turn JavaScript on for automatic verification)
Subscribe by e-mail (manage):
Ctrl+Enter »
Avatar

25 December 2012

Follow thread #1.2

FromRusWithLove

On delphi 2006 work good. if use «pngimage» you can load png files.

Your name: Your homepage:

Text & signature markup:You can use UverseWiki markup. In short: **bold**, //italic//, %%code%%, ((URL link)), >inline quote, <[ multiline quote ]>.

Humans! Please enter "J" here: (or turn JavaScript on for automatic verification)
Subscribe by e-mail (manage):
Ctrl+Enter »
Avatar

21 August 2012

Homepage Follow thread #1.1

Proger_XP

Hey, had no idea it would work in recent Delphi versions… Congrats.

Your name: Your homepage:

Text & signature markup:You can use UverseWiki markup. In short: **bold**, //italic//, %%code%%, ((URL link)), >inline quote, <[ multiline quote ]>.

Humans! Please enter "J" here: (or turn JavaScript on for automatic verification)
Subscribe by e-mail (manage):
Ctrl+Enter »