分享

Transparent TCustomcontrol

 quasiceo 2013-05-03
 
  #2  
Old 11-21-2002, 03:31 AM
Senior Member
 
Join Date: Apr 2001
Posts: 2,182
Default RE: Transparent TCustomcontrol

Transparent TCustomcontrol
hi to all,

I have a problems with making a TCustomcontrol transparent.
I added:

Procedure CreateParams(var Params: TCreateParams); override;

implenmentation

procedure TDSPTransparentPanel.CreateParams(var Params: TCreateParams);
begin
{ call the create of the params }
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle + WS_EX_Transparent;
ControlStyle := ControlStyle - [csOpaque] + [csAcceptsControls]
end;


This makes the Component transparent, but when I place an
Imagebox on it and I'am moveing the Imagebox per runtime,
the background of the TCustomcontrol losess it's
tranzparency . When I minimize and maximize the Form or when I move an other Window over it (e.g. explorer) , the transparency will be back.

So here is my Question:
What must I do to get this effect by code, to get the transparency back?
I called self.redraw , self.invalidate but without effect.


Please help me solve this Problem
Best Regards
BT
Try this:


Override its CreateParam method like this:

private // in control declaration
Procedure CreateParams( Var params: TCreateParams ); override;

Procedure TTransparentXXX.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 TTransparentXXX.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
background needs to change. Delphi container controls (like form or
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 );



Greetz,
::TeD On The NeT::

=[ QUESTIONS ]=========================================
please click Accept as Answer if my reply helped you.

=[ EXTRA INFO ]========================================
Location : Netherlands (GMT +01.00)
Languages : English, Dutch, German
Age : 25
ICQ : Be smart and figure out what my UIN is...
-------------------------------------------------------
Used OS : Win2k SR2 | Win2k SR3
Delphi # : Enterprise 5 SP2 | Enterprise 6 SP2
================================================== =====
Reply With Quote
  #3  
Old 11-21-2002, 06:07 AM
Member
 
Join Date: Nov 2001
Posts: 55
Default Transparent TCustomcontrol

I added a TImage to the create proedure in my
Transparent Component (TCustumcontrol) Create procedure:


Ibar := TImage.create(self);
Ibar.parent := self;
SetWindowLong(Ibar.parent.handle, GWL_STYLE,
GetWIndowLong(Ibar.parent.handle, GWL_STYLE )
and not WS_CLIPCHILDREN );


but when I move the Ibar per runtime the background of my Component will not updated. What can be wrong?


Please Help
Best Regards
BT
Reply With Quote
Ibar.parent := self.parent可以解决!;

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多