{"id":75,"date":"2007-05-12T13:38:05","date_gmt":"2007-05-12T11:38:05","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/transparent-controls\/"},"modified":"2007-05-12T13:40:15","modified_gmt":"2007-05-12T11:40:15","slug":"transparent-controls","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/transparent-controls\/","title":{"rendered":"Transparent Controls"},"content":{"rendered":"<p><em>ransparent Background for Controls<br \/>\n(from Peter Below)<\/p>\n<p>><br \/>\n> how would I make a component with a transparent background?<br \/>\n>  e.g. it shows the background of the parent or other components through it.<br \/>\n><br \/>\n>  <\/em><\/p>\n<p>james,<\/p>\n<p>lets play through it for a groupbox descendant, since i happen to have an<br \/>\nexample for that .<\/p>\n<p>To do that kind of stuff right, create a new control derived from TGroupbox,<br \/>\noverride its CreateParam method like this:<\/p>\n<p>[code lang=&#8221;delphi&#8221;]     private \/\/ in control declaration<br \/>\n      Procedure CreateParams( Var params: TCreateParams ); override;<\/p>\n<p>Procedure TTransparentGroupbox.CreateParams( Var params: TCreateParams );<br \/>\nbegin<br \/>\n  inherited CreateParams( params );<br \/>\n  params.ExStyle := params.ExStyle  or WS_EX_TRANSPARENT;<br \/>\nend;<\/p>\n<p>Add a handler for the WM_ERASEBKGND message:<\/p>\n<p>    Procedure WMEraseBkGnd( Var msg: TWMEraseBkGnd );<br \/>\n      message WM_ERASEBKGND;<\/p>\n<p>Procedure TTransparentGroupbox.WMEraseBkGnd( Var msg: TWMEraseBkGnd );<br \/>\nbegin<br \/>\n  SetBkMode( msg.DC, TRANSPARENT );<br \/>\n  msg.result := 1;<br \/>\nend;<br \/>\n[\/code]<br \/>\nThat is the basic frame for a TWinControl descendent. For a TGraphicsControl<br \/>\nyou would drop the CreateParams (since only WinControls have that method) and<br \/>\noverride the create constructor. After calling the inherited constructor you<br \/>\nmodify the ControlStyle of the control:<br \/>\n[code lang=&#8221;delphi&#8221;]<br \/>\n  ControlStyle := ControlStyle &#8211; [csOpaque];<\/p>\n<p>[\/code]<br \/>\nTransparency actually works better for TGraphicControls than for<br \/>\nTWinControls. The latter have problems if the control is moved or the<br \/>\nbackground needs to change. Delphi container controls (like form or panel)<br \/>\nare always created with the WS_CLIPCHILDREN style, which automatically<br \/>\nexcludes the area under child controls from updates, so the background will<br \/>\nnot be updated if required. Removing the WS_CLIPCHILDREN style from a<br \/>\ncontrols parent is possible with <\/p>\n<p>[code lang=&#8221;delphi&#8221;]  SetWindowLong( parent.handle, GWL_STYLE,<br \/>\n                 GetWIndowLong( parent.handle, GWL_STYLE )<br \/>\n                 and not WS_CLIPCHILDREN );<br \/>\n[\/code]<br \/>\nBut that may lead to accessive flicker on screen updates.                 <\/p>\n<p>Peter Below (TeamB)<br \/>\n100113.1101@compuserve.com <\/p>\n<p>[tags]Delphi, Components[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ransparent Background for Controls (from Peter Below) > > how would I make a component with a transparent background? > e.g. it shows&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[90,75],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-1d","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/75"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}