>
> I would like to have a Richedit box with a transparent background.
>
> To be more precise, I would like to be able to display the contents of a
> ..RTF file on the screen with a background graphic showing through.
>
> Does anyone know how to make this happen. Presumably, it is not just a
> matter of putting something in the background colour property (because
> I’ve looked and there is not “transparent”). However, I have seen other
> products which do have the ability to display an .RTF file on top of a
> graphic.
Von: Peter Below <
100113.1101@compuserve.com
>
Betreff: Re: Richedit on a transparent background
Datum: Dienstag, 5. Januar 1999 15:27
The rich edit control itself cannot be made transparent without a lot of
problems. But you can get it to render its text onto any kind of canvas,
e.g. a bitmap.canvas or a TImage canvas.
[code lang=”delphi”]procedure TForm1.Button2Click(Sender: TObject);
var
imagecanvas: TCanvas;
fmt: TFormatRange;
begin
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]
This assumes TImage contains a bitmap image. Add the richedit unit to your
Uses clause (the one after the Implementation keyword).
Peter Below (TeamB)
100113.1101@compuserve.com
)
No e-mail responses, please, unless explicitely requested!
[tags]Delphi, Components, RichEdit[/tags]
0 Kommentare zu “Richedit on a transparent background”