这个是透明控件的,当然也可是按钮,用的是SetWindowLong来实现的
Transparent Background for Controls
(from Peter Below)
>
> how would I make a component with a transparent background?
> e.g. it shows the background of the parent or other components through it.
>
>
james,
lets play through it for a groupbox descendant, since i happen to have an
example for that .
To do 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
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.