Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think this question is asked very often (maybe not here, but I have seen it many times before). The strange thing is, the answer almost never comes up although it is there, hidden among all people discussing the question. Maybe the question here will help improve the search process in the future, simply because it's stackoverflow :-)</p> <p>Anyway, here is the answer I found last year (see code below). Not mine, but works for me - link to <a href="http://proger.i-forge.net/RichEdit_with_transparent_background_in_Delphi_Hell_yes/OVP" rel="nofollow">author</a>. Essentially, the code defines a derived richedit with custom event handler for the WM_ERASEBACKGROUND message.</p> <pre><code>unit TransparentRichEdit; { Component made by Proger_XP | http://Proger.i-Forge.net } interface uses Windows, Messages, SysUtils, Classes, Controls, StdCtrls, ComCtrls, Graphics; type TTransparentRichEdit = class (TRichEdit) protected FCanvas: TCanvas; FBackground: TPicture; procedure CreateWnd; override; procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND; procedure SetBackground(const Value: TPicture); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property Background: TPicture read FBackground write SetBackground; end; procedure Register; implementation procedure Register; begin RegisterComponents('Miscellaneous', [TTransparentRichEdit]); end; { TTransparentRichEdit } constructor TTransparentRichEdit.Create(AOwner: TComponent); begin inherited; FCanvas := TCanvas.Create; FBackground := TPicture.Create; end; destructor TTransparentRichEdit.Destroy; begin FBackground.Free; FCanvas.Free; inherited; end; procedure TTransparentRichEdit.CreateWnd; begin inherited; SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TRANSPARENT); end; procedure TTransparentRichEdit.WMEraseBkgnd(var Message: TWMEraseBkgnd); var UpdateRect: TRect; Rgn: HRGN; ToBeErased: Boolean; Mem: TBitmap; begin ToBeErased:= false; Mem := TBitmap.Create; try Mem.Width := ClientWidth; Mem.Height := ClientHeight; FCanvas.Handle := Message.DC; Message.Result := 1; if not GetUpdateRect(Handle, UpdateRect, ToBeErased) then UpdateRect := Rect(0, 0, ClientWidth, ClientHeight); with UpdateRect do Rgn := CreateRectRgn(Left, Top, Right, Bottom); SelectClipRgn(FCanvas.Handle, Rgn); FCanvas.Draw(0, 0, FBackground.Graphic); finally Mem.Free; end; end; procedure TTransparentRichEdit.SetBackground(const Value: TPicture); begin FBackground.Assign(Value); Repaint; end; end. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload