透明RichEdit(只读)
RichEdit
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,do
es anybody know a free Component, that cando
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.
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 fmtdo
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;
透明 WinControls
Components
Transparent WinControls
In article <7kv799$efd8@forums.borland.com>, Robert wrote:
> WMEraseBkgnd message fills the TWincontrol with the brush color of the
> control, that makes the control opaque. Is it posible to make a
> TWincontrol transparent?
Well, you have half the answer: since it is WM_ERASEBKGND that causes
the background fill, trap the message and block it.
Here is my standard reply on this transparent issue:
> Please give me help on how to make a descendent class of TGroupBox
> transparent. Thanks in advance.
Scott,
a quick &
dirty method is
groupbox1.Brush.style := bsclear;
groupbox1.handleneeded;
setwindowlong( groupbox1.handle, GWL_EXSTYLE, WS_EX_TRANSPARENT );
in the forms OnCreate event handler.
Todo
that kind of stuff right, create a new control derived from
TGroupbox, override its CreateParam method like this:
private // in control declaration
Procedure CreateParams( Var params: TCreateParams );
override;
Procedure TTransparentGroupbox.CreateParams( Var params: TCreateParams
);
begin
inherited CreateParams( params );
params.ExStyle := params.ExStyle or WS_EX_TRANSPARENT;
end;
Add a handler for the WM_ERASEBKGND message:
Procedure WMEraseBkGnd( Var msg: TWMEraseBkGnd );
message WM_ERASEBKGND;
Procedure TTransparentGroupbox.WMEraseBkGnd( Var msg: TWMEraseBkGnd );
begin
SetBkMode( msg.DC, TRANSPARENT );
msg.result := 1;
end;
That is the basic frame for a TWinControl descendent. For a
TGraphicsControl you would drop the CreateParams (since only WinControls
have that method) and override the create constructor. After calling the
inherited constructor you modify the ControlStyle of the control:
ControlStyle := ControlStyle - [csOpaque];
Transparency actually works better for TGraphicControls than for
TWinControls. The latter have problems if the control is moved or the
panel) are always created with the WS_CLIPCHILDREN style, which
automatically excludes the area under child controls from updates, so
the background will not be updated if required. Removing the
WS_CLIPCHILDREN style from a controls parent is possible with
SetWindowLong( parent.handle, GWL_STYLE,
GetWIndowLong( parent.handle, GWL_STYLE )
and not WS_CLIPCHILDREN );
But that may lead to accessive flicker on screen updates.
Peter Below (TeamB) 100113.1101@compuserve.com)
No e-mail responses, please, unless explicitly requested!