Mastodon
Programmierung

Transparent RichEdit (just display)

“M. Schubert” wrote:

> Is there a way to make a RichEdit-Component transparent, so that only
> the Text ist displayed and the background shines through ?
>
> If not, does anybody know a free Component, that can do this ?
>
> Thanx in advance
>
> Markward

My thanks to Peter Below for this code which allows you to display Rich
Text so that the background shines through. Note that the RichEdit
component itself is not visible – so you cannot edit the text that you
can see.

Hope it helps.

[code lang=”delphi”]implementation
uses richedit;
{$R *.DFM}

procedure TForm1.Button2Click(Sender: TObject);
var
imagecanvas: TCanvas;
fmt: TFormatRange;
begin
RichEdit1.lines.LoadFromFile(‘text.rtf’);
imagecanvas := image1.canvas;

with fmt do begin
hdc:= imagecanvas.handle;
hdcTarget:= hdc;
// rect needs to be specified in twips (1/1440 inch) as unit
rc:= Rect(0, 0,
imagecanvas.cliprect.right * 1440 div pixelsperinch,
imagecanvas.cliprect.bottom * 1440 div pixelsperinch
);
rcPage:= rc;
chrg.cpMin := 0;
chrg.cpMax := richedit1.GetTextLen;
end;

SetBkMode( imagecanvas.Handle, TRANSPARENT );
richedit1.perform( EM_FORMATRANGE, 1, integer( @fmt ));
// next call frees some cached data
richedit1.perform( EM_FORMATRANGE, 0, 0 );
image1.refresh;
// refresh is necessary since the control only refreshes automatically
// if a canvas method is used to change its content.

end;[/code]

[tags]Delphi, Components, RichEdit[/tags]

0 Kommentare zu “Transparent RichEdit (just display)

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.