1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
{
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.
}
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;
{
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!
} |
Partager