Lazarus

Miscellaneous => Other => Topic started by: majid.ebru on May 05, 2017, 12:15:41 pm

Title: [SOLVED]transparent TPanel?
Post by: majid.ebru on May 05, 2017, 12:15:41 pm
Hi
.

How to make transparent TPanel?
or
how to set alphablend to panel?
Title: Re: transparent TPanel?
Post by: RAW on May 05, 2017, 12:35:42 pm
The easiest way would probably be to not use a TPanel...  :P

I saw someone who did that with Delphi but it was not possible to scroll something inside that panel.
Good Luck !


EDIT:
Another easy way would be to use a TImage inside that TPanel with a part of the background image... (not the best though).
Title: Re: transparent TPanel?
Post by: majid.ebru on May 05, 2017, 06:49:10 pm

Another easy way would be to use a TImage inside that TPanel with a part of the background image... (not the best though).
hi
i need container element and Timage is not?
Title: Re: transparent TPanel?
Post by: kupferstecher on May 05, 2017, 09:38:04 pm
Some time before I also searched for it, and didn't find any solution for Lazarus (doesn't work in the way it does for Delphi).
In the meantime I stumbled across the below link, containing code for a transparent panel. No idea if/how it works though.

There is a remark in the description, it roughly says: "The transparent panel is realized through capturing the picture of the parent, thus there may not be any other component under the panel, otherwise it will be hidden."

http://lc51746.blog.163.com/blog/static/123509108200982802026564/

If you try it please let us know if it works.
Regards
Title: Re: transparent TPanel?
Post by: majid.ebru on May 05, 2017, 11:32:11 pm
Quote
Lazarus中没有透明Panel组件,就自己写了一个,经过一番折腾,总算是设计期和运行期都可以正确的透明了。

注意,透明Panel是通过抓取Parent图片的方式实现的,因此Panel下不能放置别的组件,否则会被背景图挡住。

我写了一个具有背景图片功能的Panel组件,可以结合透明Panel一起使用,效果非常不错,详情参考《Lazarus 的具有背景图片的Panel组件》

下面是组件源码

Google translate :
Quote
Lazarus no transparent Panel components, write their own one, after some toss, finally the design period and the operation period can be correct and transparent.

Note that the transparent Panel is achieved by capturing the Parent image, so the Panel can not place other components, otherwise it will be blocked by the background.

I have written a Panel component with background image functionality that can be used in conjunction with a transparent Panel. The results are very good. For details, refer to "Lazarus Panel Components with Background Pictures"

The following is the component source
Code: Pascal  [Select][+][-]
  1. unit uTransparentPanel;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.  
  9.   Classes, SysUtils, LMessages, Forms, Controls, Graphics, LCLType, types, Windows;
  10.  
  11. type
  12.  
  13.   { TTransparentPanel }
  14.  
  15.   TTransparentPanel = class(TCustomControl)
  16.  
  17.   private
  18.  
  19.     fBuffer: Graphics.TBitmap;
  20.  
  21.     fBufferChanged : boolean;
  22.  
  23.     procedure SetColor(Value: TColor); override;
  24.  
  25.   protected
  26.  
  27.     function getBuffer : Graphics.TBitmap; virtual;
  28.  
  29.     procedure WMWindowPosChanged(var Message: TLMWindowPosChanged); message LM_WINDOWPOSCHANGED;
  30.  
  31.     procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;
  32.  
  33.     procedure CreateParams(var Params: TCreateParams);
  34.  
  35.     procedure Paint; override;
  36.  
  37.     procedure Resize; override;
  38.  
  39.     procedure redrawBackgroundBuffer(var buffer : Graphics.TBitmap); virtual;
  40.  
  41.     function getBufferChanged : boolean; virtual;
  42.  
  43.     procedure setBufferChanged(val : boolean); virtual;
  44.  
  45.     procedure Invalidate; override;
  46.  
  47.   public
  48.  
  49.     constructor Create(AOwner : TComponent); override;
  50.  
  51.     destructor Destroy; override;
  52.  
  53.   published
  54.  
  55.     property OnPaint;
  56.  
  57.     property Color;
  58.  
  59.     property Align;
  60.  
  61.     property Height;
  62.  
  63.     property Cursor;
  64.  
  65.     property HelpContext;
  66.  
  67.     property HelpType;
  68.  
  69.     property Hint;
  70.  
  71.     property Left;
  72.  
  73.     property Name;
  74.  
  75.     property Tag;
  76.  
  77.     property Top;
  78.  
  79.     property Width;
  80.  
  81.     property Anchors;
  82.  
  83.     property Constraints;
  84.  
  85.   end;
  86.  
  87. procedure Register;
  88.  
  89. implementation
  90.  
  91. procedure Register;
  92.  
  93. begin
  94.  
  95.   RegisterComponents('aess',[TTransparentPanel]);
  96.  
  97. end;
  98.  
  99. { TTransparentPanel }
  100.  
  101. procedure TTransparentPanel.SetColor(Value: TColor);
  102.  
  103. begin
  104.  
  105.   inherited SetColor(Value);
  106.  
  107.   RecreateWnd(Self);
  108.  
  109. end;
  110.  
  111. function TTransparentPanel.getBuffer: Graphics.TBitmap;
  112.  
  113. begin
  114.  
  115.   Result := fBuffer;
  116.  
  117. end;
  118.  
  119. procedure TTransparentPanel.WMWindowPosChanged(var Message: TLMWindowPosChanged);
  120.  
  121. begin
  122.  
  123.   setBufferChanged(true);
  124.  
  125.   Invalidate;
  126.  
  127.   inherited;
  128.  
  129. end;
  130.  
  131. procedure TTransparentPanel.WMEraseBkgnd(var Message: TLMEraseBkgnd);
  132.  
  133. begin
  134.  
  135.   Message.Result := 1;
  136.  
  137. end;
  138.  
  139. procedure TTransparentPanel.CreateParams(var Params: TCreateParams);
  140.  
  141. begin
  142.  
  143.   inherited CreateParams(Params);
  144.  
  145.   params.exstyle := params.exstyle or WS_EX_TRANSPARENT;
  146.  
  147. end;
  148.  
  149. procedure TTransparentPanel.Paint;
  150.  
  151. begin
  152.  
  153.   if getBufferChanged then
  154.  
  155.   begin
  156.  
  157.     redrawBackgroundBuffer(fBuffer);
  158.  
  159.     setBufferChanged(false);
  160.  
  161.   end;
  162.  
  163.   Canvas.Draw(0, 0, fBuffer);
  164.  
  165.   if assigned(OnPaint) then
  166.  
  167.     OnPaint(Self);
  168.  
  169. end;
  170.  
  171. procedure TTransparentPanel.Resize;
  172.  
  173. begin
  174.  
  175.   setBufferChanged(true);
  176.  
  177.   Invalidate;
  178.  
  179.   inherited Resize;
  180.  
  181. end;
  182.  
  183. procedure TTransparentPanel.redrawBackgroundBuffer(var buffer : Graphics.TBitmap);
  184.  
  185. var
  186.  
  187.   rDest : TRect;
  188.  
  189.   bmp : Graphics.TBitmap;
  190.  
  191. begin
  192.  
  193.   bmp := Graphics.TBitmap.Create;
  194.  
  195.   try
  196.  
  197.     bmp.PixelFormat := pf24bit;
  198.  
  199.     bmp.Width := Parent.Width;
  200.  
  201.     bmp.Height := Parent.Height;
  202.  
  203.     bmp.TransparentColor:= Self.Color;
  204.  
  205.     bmp.Canvas.brush.Color:=TCustomForm(parent).Color;
  206.  
  207.     bmp.Canvas.FillRect(types.rect(0,0,bmp.width,bmp.height));
  208.  
  209.     SendMessage(parent.Handle, WM_PAINT, bmp.Canvas.handle, 0);
  210.  
  211.     Application.ProcessMessages;
  212.  
  213.     buffer.Width:= Self.Width;
  214.  
  215.     buffer.Height := Self.Height;
  216.  
  217.     rDest := types.Rect(0,0,Width, Height);
  218.  
  219.     buffer.Canvas.CopyRect(rDest, bmp.Canvas, BoundsRect);
  220.  
  221.   finally
  222.  
  223.     freeandnil(bmp);
  224.  
  225.   end;//fianlly
  226.  
  227. end;
  228.  
  229. function TTransparentPanel.getBufferChanged: boolean;
  230.  
  231. begin
  232.  
  233.   Result := fBufferChanged;
  234.  
  235. end;
  236.  
  237. procedure TTransparentPanel.setBufferChanged(val: boolean);
  238.  
  239. begin
  240.  
  241.   fBufferChanged := val;
  242.  
  243. end;
  244.  
  245. procedure TTransparentPanel.Invalidate;
  246.  
  247. begin
  248.  
  249.   if assigned(parent) and parent.HandleAllocated then
  250.  
  251.   begin
  252.  
  253.     InvalidateRect(parent.Handle, BoundsRect, true);
  254.  
  255.     inherited Invalidate;
  256.  
  257.   end
  258.  
  259.   else
  260.  
  261.     inherited Invalidate;
  262.  
  263. end;
  264.  
  265. constructor TTransparentPanel.Create(AOwner: TComponent);
  266.  
  267. begin
  268.  
  269.   inherited Create(AOwner);
  270.  
  271.   fBuffer := Graphics.TBitmap.Create;
  272.  
  273.   ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
  274.  
  275.   csDoubleClicks, csReplicatable];
  276.  
  277.   Width := 200;
  278.  
  279.   Height := 150;
  280.  
  281.   ParentCtl3d := False;
  282.  
  283.   Ctl3D := False;
  284.  
  285.   ParentColor := False;
  286.  
  287.   fBufferChanged:= false;
  288.  
  289.   inherited Color := clWindow;
  290.  
  291. end;
  292.  
  293. destructor TTransparentPanel.Destroy;
  294.  
  295. begin
  296.  
  297.   fBuffer.Free;
  298.  
  299.   inherited Destroy;
  300.  
  301. end;
  302.  
  303. end.
  304.  

.
.
Thank you

but how can i use this ?!?!?
Title: Re: transparent TPanel?
Post by: wp on May 06, 2017, 12:12:22 am
In the attachment, there's a quick test in which the panel extends over the entire form which is painted with a gradient background; the panel also contains a button and a radiogroup.

I had to fix a couple of issues (compilation error due to properties Ctrl3D and ParentCtrl3D not existing in Lazarus, remove Windows unit to make the component cross-platform, add missing override directive to CreateParams).

The panel really is transparent but causes a lot of flicker when the form is resized.

If you can live with this you must add the unit to a package and install the package into the ide (http://wiki.lazarus.freepascal.org/How_To_Write_Lazarus_Component). After that the panel will appear in the component palette for usage like any other component.
Title: Re: transparent TPanel?
Post by: jc99 on May 06, 2017, 12:22:21 am
@majid.ebru
What do you try to do ?
Do your users have to work with Controls e.G: Buttons under the transparent panel ? -> try shaped controls
Do you only need it for a cool blending effect ?-> Try TImage or BGRA

The transparent panel is just a Transparent Panel, but alpha-blending might be possible (but only for the background).
Title: Re: transparent TPanel?
Post by: majid.ebru on May 06, 2017, 10:21:38 am
thanks for answer.
.
in this topic (http://forum.lazarus.freepascal.org/index.php/topic,36470.0.html) i show what i need and Mr.jmpessoa  (http://forum.lazarus.freepascal.org/index.php?action=profile;u=47362)solved it
.
i just have a beauty form and both of my program (OS : android and windows ) Like each other.
.
the TShape element is not container and i don't find any samlpe of BGRA aboute alpha transparent.
.
i just find this post (http://forum.lazarus.freepascal.org/index.php/topic,30420.msg194165.html#msg194165).
.
this program sets Blur panel
Title: Re: transparent TPanel?
Post by: kupferstecher on May 06, 2017, 07:17:50 pm
The panel really is transparent but causes a lot of flicker when the form is resized.
Now I also made a try. Same here, a lot of flickering, even when entering the form with the mouse. Anyone any idea how to improve that?

Regards
Title: Re: transparent TPanel?
Post by: majid.ebru on May 26, 2017, 03:57:24 pm
Quote
Lazarus中没有透明Panel组件,就自己写了一个,经过一番折腾,总算是设计期和运行期都可以正确的透明了。

注意,透明Panel是通过抓取Parent图片的方式实现的,因此Panel下不能放置别的组件,否则会被背景图挡住。

我写了一个具有背景图片功能的Panel组件,可以结合透明Panel一起使用,效果非常不错,详情参考《Lazarus 的具有背景图片的Panel组件》

下面是组件源码

Google translate :
Quote
Lazarus no transparent Panel components, write their own one, after some toss, finally the design period and the operation period can be correct and transparent.

Note that the transparent Panel is achieved by capturing the Parent image, so the Panel can not place other components, otherwise it will be blocked by the background.

I have written a Panel component with background image functionality that can be used in conjunction with a transparent Panel. The results are very good. For details, refer to "Lazarus Panel Components with Background Pictures"

The following is the component source
Code: Pascal  [Select][+][-]
  1. unit uTransparentPanel;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.  
  9.   Classes, SysUtils, LMessages, Forms, Controls, Graphics, LCLType, types, Windows;
  10.  
  11. type
  12.  
  13.   { TTransparentPanel }
  14.  
  15.   TTransparentPanel = class(TCustomControl)
  16.  
  17.   private
  18.  
  19.     fBuffer: Graphics.TBitmap;
  20.  
  21.     fBufferChanged : boolean;
  22.  
  23.     procedure SetColor(Value: TColor); override;
  24.  
  25.   protected
  26.  
  27.     function getBuffer : Graphics.TBitmap; virtual;
  28.  
  29.     procedure WMWindowPosChanged(var Message: TLMWindowPosChanged); message LM_WINDOWPOSCHANGED;
  30.  
  31.     procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;
  32.  
  33.     procedure CreateParams(var Params: TCreateParams);
  34.  
  35.     procedure Paint; override;
  36.  
  37.     procedure Resize; override;
  38.  
  39.     procedure redrawBackgroundBuffer(var buffer : Graphics.TBitmap); virtual;
  40.  
  41.     function getBufferChanged : boolean; virtual;
  42.  
  43.     procedure setBufferChanged(val : boolean); virtual;
  44.  
  45.     procedure Invalidate; override;
  46.  
  47.   public
  48.  
  49.     constructor Create(AOwner : TComponent); override;
  50.  
  51.     destructor Destroy; override;
  52.  
  53.   published
  54.  
  55.     property OnPaint;
  56.  
  57.     property Color;
  58.  
  59.     property Align;
  60.  
  61.     property Height;
  62.  
  63.     property Cursor;
  64.  
  65.     property HelpContext;
  66.  
  67.     property HelpType;
  68.  
  69.     property Hint;
  70.  
  71.     property Left;
  72.  
  73.     property Name;
  74.  
  75.     property Tag;
  76.  
  77.     property Top;
  78.  
  79.     property Width;
  80.  
  81.     property Anchors;
  82.  
  83.     property Constraints;
  84.  
  85.   end;
  86.  
  87. procedure Register;
  88.  
  89. implementation
  90.  
  91. procedure Register;
  92.  
  93. begin
  94.  
  95.   RegisterComponents('aess',[TTransparentPanel]);
  96.  
  97. end;
  98.  
  99. { TTransparentPanel }
  100.  
  101. procedure TTransparentPanel.SetColor(Value: TColor);
  102.  
  103. begin
  104.  
  105.   inherited SetColor(Value);
  106.  
  107.   RecreateWnd(Self);
  108.  
  109. end;
  110.  
  111. function TTransparentPanel.getBuffer: Graphics.TBitmap;
  112.  
  113. begin
  114.  
  115.   Result := fBuffer;
  116.  
  117. end;
  118.  
  119. procedure TTransparentPanel.WMWindowPosChanged(var Message: TLMWindowPosChanged);
  120.  
  121. begin
  122.  
  123.   setBufferChanged(true);
  124.  
  125.   Invalidate;
  126.  
  127.   inherited;
  128.  
  129. end;
  130.  
  131. procedure TTransparentPanel.WMEraseBkgnd(var Message: TLMEraseBkgnd);
  132.  
  133. begin
  134.  
  135.   Message.Result := 1;
  136.  
  137. end;
  138.  
  139. procedure TTransparentPanel.CreateParams(var Params: TCreateParams);
  140.  
  141. begin
  142.  
  143.   inherited CreateParams(Params);
  144.  
  145.   params.exstyle := params.exstyle or WS_EX_TRANSPARENT;
  146.  
  147. end;
  148.  
  149. procedure TTransparentPanel.Paint;
  150.  
  151. begin
  152.  
  153.   if getBufferChanged then
  154.  
  155.   begin
  156.  
  157.     redrawBackgroundBuffer(fBuffer);
  158.  
  159.     setBufferChanged(false);
  160.  
  161.   end;
  162.  
  163.   Canvas.Draw(0, 0, fBuffer);
  164.  
  165.   if assigned(OnPaint) then
  166.  
  167.     OnPaint(Self);
  168.  
  169. end;
  170.  
  171. procedure TTransparentPanel.Resize;
  172.  
  173. begin
  174.  
  175.   setBufferChanged(true);
  176.  
  177.   Invalidate;
  178.  
  179.   inherited Resize;
  180.  
  181. end;
  182.  
  183. procedure TTransparentPanel.redrawBackgroundBuffer(var buffer : Graphics.TBitmap);
  184.  
  185. var
  186.  
  187.   rDest : TRect;
  188.  
  189.   bmp : Graphics.TBitmap;
  190.  
  191. begin
  192.  
  193.   bmp := Graphics.TBitmap.Create;
  194.  
  195.   try
  196.  
  197.     bmp.PixelFormat := pf24bit;
  198.  
  199.     bmp.Width := Parent.Width;
  200.  
  201.     bmp.Height := Parent.Height;
  202.  
  203.     bmp.TransparentColor:= Self.Color;
  204.  
  205.     bmp.Canvas.brush.Color:=TCustomForm(parent).Color;
  206.  
  207.     bmp.Canvas.FillRect(types.rect(0,0,bmp.width,bmp.height));
  208.  
  209.     SendMessage(parent.Handle, WM_PAINT, bmp.Canvas.handle, 0);
  210.  
  211.     Application.ProcessMessages;
  212.  
  213.     buffer.Width:= Self.Width;
  214.  
  215.     buffer.Height := Self.Height;
  216.  
  217.     rDest := types.Rect(0,0,Width, Height);
  218.  
  219.     buffer.Canvas.CopyRect(rDest, bmp.Canvas, BoundsRect);
  220.  
  221.   finally
  222.  
  223.     freeandnil(bmp);
  224.  
  225.   end;//fianlly
  226.  
  227. end;
  228.  
  229. function TTransparentPanel.getBufferChanged: boolean;
  230.  
  231. begin
  232.  
  233.   Result := fBufferChanged;
  234.  
  235. end;
  236.  
  237. procedure TTransparentPanel.setBufferChanged(val: boolean);
  238.  
  239. begin
  240.  
  241.   fBufferChanged := val;
  242.  
  243. end;
  244.  
  245. procedure TTransparentPanel.Invalidate;
  246.  
  247. begin
  248.  
  249.   if assigned(parent) and parent.HandleAllocated then
  250.  
  251.   begin
  252.  
  253.     InvalidateRect(parent.Handle, BoundsRect, true);
  254.  
  255.     inherited Invalidate;
  256.  
  257.   end
  258.  
  259.   else
  260.  
  261.     inherited Invalidate;
  262.  
  263. end;
  264.  
  265. constructor TTransparentPanel.Create(AOwner: TComponent);
  266.  
  267. begin
  268.  
  269.   inherited Create(AOwner);
  270.  
  271.   fBuffer := Graphics.TBitmap.Create;
  272.  
  273.   ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
  274.  
  275.   csDoubleClicks, csReplicatable];
  276.  
  277.   Width := 200;
  278.  
  279.   Height := 150;
  280.  
  281.   ParentCtl3d := False;
  282.  
  283.   Ctl3D := False;
  284.  
  285.   ParentColor := False;
  286.  
  287.   fBufferChanged:= false;
  288.  
  289.   inherited Color := clWindow;
  290.  
  291. end;
  292.  
  293. destructor TTransparentPanel.Destroy;
  294.  
  295. begin
  296.  
  297.   fBuffer.Free;
  298.  
  299.   inherited Destroy;
  300.  
  301. end;
  302.  
  303. end.
  304.  


does anyone has idea ?
or
help who  i can use this unit???
Title: Re: transparent TPanel?
Post by: majid.ebru on May 26, 2017, 04:10:18 pm
in this topic  (http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Transparent-Container-Panel-in-LCL-td4026224.html) talk aboute transparent.
but i am beginner and i don't understand.
help and guide me please
Title: Re: transparent TPanel?
Post by: SunyD on May 26, 2017, 06:01:57 pm
This is very easy, at least on Windows:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Panel1.ControlStyle := Panel1.ControlStyle - [csOpaque] + [csParentBackground];
  4. end;
  5.  
  6.  
Title: Re: transparent TPanel?
Post by: jc99 on May 26, 2017, 07:07:48 pm
But they are talking about a Transparent (fully clear) region around a control to give it the shape you want. Even more the part that ia shaped out is not existing for the LCL this way you can click through, if you have an other control (e.G: a button) behind the control/panel. Sometimes this is also a nice feature.
see: https://github.com/joecare99/Public/master/idee/FPC (https://github.com/joecare99/Public/master/idee/FPC) Prj_Clock.*
       https://github.com/joecare99/Public/master/idee/source (https://github.com/joecare99/Public/master/idee/source) frm_clock*.*
       
But as I understood your problem (like the picture in the other thread)
You have a picture as a background.
Than you have one or more panels with other components on it that look half transparent (transparent but a little darker).
Since there is no native way in LCL you do it on your own.
  As it only has to look half transparent all you have to do is take a panel and paint the part of the background that is covered by the panel on the background of the panel.
  ... and since you have the drawing procedures in your hand you can do what ever you want with the picture (lighten it, darken it, blur it, rotate zoom ... and here BGRA comes handy
       because it offers many of these image-manipulation-techniques.
The code from the chinese site offers you the ability to put a screenshot of what's behind the panel on the panel. To do so it has to make the panel invisible itself, for any screenshot taken.
therefore the flickering. To reduce that you can either take screenshot only when it's necessary (e.G: when there are actual changes behind the panel ), or you can make a screenshot from a copy of your form outside the visible part of the screen.
Title: Re: transparent TPanel?
Post by: jc99 on May 26, 2017, 07:13:05 pm
This is very easy, at least on Windows:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Panel1.ControlStyle := Panel1.ControlStyle - [csOpaque] + [csParentBackground];
  4. end;
  5.  
  6.  
Your solution is only half the way, look at picture, but maybe it's enough   
Title: Re: transparent TPanel?
Post by: avra on May 26, 2017, 07:36:35 pm
Not a transparent panel, but maybe you can find something you want here:
https://www.getlazarus.org/forums/viewtopic.php?f=18&t=40
https://www.getlazarus.org/forums/viewtopic.php?f=18&t=48
https://www.getlazarus.org/forums/viewforum.php?f=18
http://lazplanet.blogspot.rs/2013/04/make-your-forms-transparent.html
https://www.youtube.com/watch?v=oPFyQI0GF_o
Title: Re: transparent TPanel?
Post by: jc99 on May 26, 2017, 07:49:02 pm
Try that, only a proove of concept but have a try:
https://github.com/joecare99/Public/blob/master/Projects/bin/x86_64-win64/prj_TestTranspPanel_easy.exe
Title: Re: transparent TPanel?
Post by: majid.ebru on May 26, 2017, 08:19:59 pm
thank you
 :) ;) :D ;D
Title: Re: transparent TPanel?
Post by: jc99 on May 26, 2017, 08:30:07 pm
Two Screenshots:
With the checkbox you switch the panel on and off.
Title: Re: transparent TPanel?
Post by: taazz on May 26, 2017, 10:22:24 pm
Here is a quick and dirty implementation. Its Slow,(really slow but it shows the required steps). I wrote it to test Soner's post for transparency.
https://sourceforge.net/projects/evssimplegraph/files/Release/Samples/TranslucentPanel.rar/download (https://sourceforge.net/projects/evssimplegraph/files/Release/Samples/TranslucentPanel.rar/download)

EDIT:
oh I just show jc99's "more interesting" solution. Really nice! thanks.
Title: Re: transparent TPanel?
Post by: RAW on May 26, 2017, 10:56:38 pm
Unfortunately this is not working with a classic theme...  :'(
Funny, I can scroll a label inside the panel and it looks good... but yeah, it's too slow...  :D
Title: Re: transparent TPanel?
Post by: taazz on May 27, 2017, 01:48:11 am
Unfortunately this is not working with a classic theme...  :'(
Oh! I'll disable the aero theming and see how it works thanks for the heads up.
Funny, I can scroll a label inside the panel and it looks good... but yeah, it's too slow...  :D
Yeah. There are a number of ways to make it faster inlcuding the alphablend function from the windows API. I'll take a closer look when I get a bit more time.
Title: Re: transparent TPanel?
Post by: jc99 on May 27, 2017, 08:50:42 am
@taazz:
Making the scrolling of the Label on the panel faster is no problem:
What needs time is the pixel-by-pixel-calculation of the background in the onPaint-method.
So: if you only do the necessary stuff at the necessary point of time. (and nowadays you have enough mem to store precalulated data) you get a BIG acceleration.
1. Calculating the darkend, or maybe somehow other transformed background of the form can be done at the very start of the program, maybe in a second task. It can be even done externaly (e.G: with Paint.net) like I did and be stored in the App. I mean the complete background of the form.
2. in the onpaint-method you "only" have to BitBlit the needed part of that precalculated background on the panel.
[edit]
2a) If you put a Timage on the panel even the redrawing when something is moving on the panel (e.G: the label, mentioned above) is done by the system, and you only have to paint on the Image when you move or resize the panel.
 
Title: Re: transparent TPanel?
Post by: Pascal on July 12, 2017, 01:52:53 pm
This is very easy, at least on Windows:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Panel1.ControlStyle := Panel1.ControlStyle - [csOpaque] + [csParentBackground];
  4. end;
  5.  
  6.  

Doesn't this work on other Platforms?
Title: Re: [SOLVED]transparent TPanel?
Post by: wp on July 12, 2017, 05:05:13 pm
No, Windows only...
Title: Re: [SOLVED]transparent TPanel?
Post by: Pascal on July 12, 2017, 05:54:22 pm
Is there a way to do it cross platform?
Title: Re: [SOLVED]transparent TPanel?
Post by: wp on July 12, 2017, 06:00:53 pm
Nothing is impossible, but nobody did it so far (at least as far as I know). Even the current TPanel behaves differently on different platforms: Win: opaque, gtk2: transparent, qt: opaque. (Maybe I am confusing gtk2 and qt here, but I am sure that in my recent test one of them was transparent).
Title: Re: [SOLVED]transparent TPanel?
Post by: majid.ebru on July 13, 2017, 06:49:03 am
Is there a way to do it cross platform?

Hi

if it is possible ,use BGRA component
TinyPortal © 2005-2018