Form transparent by regions lazarus / 31-LCL ---------------------------------------------------------------------- pmesquita · 2021-12-26 13:53 Folks, I need to create a form that has transparency but except for a part that will be displayed a TPanel with several objects in it and this cannot be applied to transparency... Does anyone have any idea if there is a way to do this? Here's an example using SetLayeredWindowAttributes that I believe is the solution... ---------------------------------------------------------------------- balazsszekely · 2021-12-26 14:36 Quote from: pmesquita on December 26, 2021, 02:53:13 pmFolks, I need to create a form that has transparency but except for a part that will be displayed a TPanel with several objects in it and this cannot be applied to transparency... Does anyone have any idea if there is a way to do this? Here's an example using SetLayeredWindowAttributes that I believe is the solution... Try something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure CreateTransparentForm(AForm: TForm; APanel: TPanel);var  FormRegion, PanelRegion: HRGN;begin  FormRegion := CreateRectRgn(0, 0, AForm.Width, AForm.Height);  try    PanelRegion := CreateRectRgn(APanel.Left, APanel.Top, APanel.Left + APanel.Width, APanel.Top + APanel.Height);    try      CombineRgn(FormRegion, FormRegion, PanelRegion, RGN_AND);    finally      DeleteObject(PanelRegion);    end;    SetWindowRgn(AForm.Handle, FormRegion, True);  finally    DeleteObject(FormRegion);  end;end; procedure TForm1.FormCreate(Sender: TObject);begin  CreateTransparentForm(Form1, Panel1);end; procedure TForm1.CreateParams(var Params: TCreateParams);begin  inherited CreateParams(Params);  Self.BorderStyle := bsNone;end; ---------------------------------------------------------------------- pmesquita · 2021-12-26 15:05 GetMem thanks for the reply.. This is not quite what I need, I've been looking at this alternative but without success so far... But my idea is: the entire area around Panel1, as in my example, is 60% transparent (AlphaBlend) and only Panel1 and its objects are opaque... Because I need to "see" Panel1 but at the same time "see" the content of the form in which it is contained... style as android messagebox where the background appears blurred... This is what I need... I'll use your example to see if I can create a region under the panel where windows ignore the transparency in it and its objects... ---------------------------------------------------------------------- jamie · 2021-12-26 16:50 Use the standard facilities of the form with alphablend and set the shade to 128 for example, in the oncreateform event or somewhere at some point, set the form's brush.color  := clBlack.  Use a Dialog form that you can create as a secondary form and show it over the form1 when in the state that you need this.  Populate the Dialog with all the needed controls etc.  of course this will direct all input to the dialog form when doing so. ---------------------------------------------------------------------- pmesquita · 2021-12-26 20:56 I even thought about it and so far it is the only reasonable solution to the problem. I was trying to avoid this way of creating a Form just to get the "transparent background" effect but all the effects I managed to do as you said... I will add improvements to the TODO for this situation and if there is any solution posted here for the staff Thanks... ---------------------------------------------------------------------- mike_p · 2021-12-27 08:40 Would you be happy to have some parts of your form transparent and other part opaque? If so, use chromakey (ie replace a specified colour with transparency) A while back, working in Delphi 5, I created a component that could be dropped on a form that would provide Alphablend and Chromakey that worked in design time and runtime. If you're interested I'll dig out some code samples. ---------------------------------------------------------------------- pmesquita · 2021-12-28 11:15 Basically this is what I need, that the whole area around a TPanel is semi transparent, if you have any ideas or code to do this I thank you.. ---------------------------------------------------------------------- ASerge · 2021-12-28 17:31 Quote from: pmesquita on December 28, 2021, 12:15:07 pm...if you have any ideas or code to do this I thank you.. @jamie idea. Example. Create a new application. Create a new panel in the form with any controls and two buttons: btnFocusOnPanel outside the panel and btnLeavePanel inside the panel. Add the code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  AlphaBlendValue := 200;end; procedure TForm1.btnFocusOnPanelClick(Sender: TObject);begin  if not AlphaBlend then  begin    AlphaBlend := True;    PanelFly(Panel1);  end;end; procedure TForm1.btnLeavePanelClick(Sender: TObject);begin  if AlphaBlend then  begin    AlphaBlend := False;    PanelLand(Panel1);  end;end; and the code for the "flying" panel in front of the code above: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure PanelFly(Panel: TPanel);var  PanelPos: TPoint;  FlyForm: TForm;  FlyFormRect: TRect;begin  PanelPos := Panel.BoundsRect.TopLeft;  Panel.Hide;  FlyForm := TForm.Create(Application);  FlyForm.BorderStyle := bsNone;  FlyForm.FormStyle := fsStayOnTop;  FlyFormRect := Panel.ClientRect;  FlyFormRect.Offset(Panel.Parent.ClientToScreen(PanelPos));  FlyForm.BoundsRect := FlyFormRect;  Panel.Left := 0;  Panel.Top := 0;  Panel.Parent := FlyForm;  Panel.Show;  FlyForm.ShowModal;end; procedure PanelLand(Panel: TPanel);var  PanelPos: TPoint;  FlyForm: TForm;  OwnerForm: TForm;begin  FlyForm := Panel.Parent as TForm;  FlyForm.ModalResult := mrCancel;  OwnerForm := Panel.Owner as TForm;  PanelPos := OwnerForm.ScreenToClient(FlyForm.BoundsRect.TopLeft);  Panel.Hide;  Panel.Parent := OwnerForm;  Panel.Left := PanelPos.X;  Panel.Top := PanelPos.Y;  Panel.Show;  FlyForm.Release;end; ---------------------------------------------------------------------- Tony Stone · 2021-12-29 12:24 I would take a look at some functions in the Cross Codebot library here.  I think I saw something for odd shaped forms. https://github.com/sysrpl/Cross.Codebot ---------------------------------------------------------------------- pcurtis · 2021-12-29 17:47 What OS? ---------------------------------------------------------------------- pmesquita · 2021-12-29 17:56 Quote from: pcurtis on December 29, 2021, 06:47:43 pmWhat OS? Windows 10 x64 ---------------------------------------------------------------------- pmesquita · 2021-12-29 17:56 Quote from: Tony Stone on December 29, 2021, 01:24:51 pmI would take a look at some functions in the Cross Codebot library here.  I think I saw something for odd shaped forms. https://github.com/sysrpl/Cross.Codebot I'll take a calm look later... ---------------------------------------------------------------------- pcurtis · 2021-12-29 18:09 Try this (attachment)