Recent

Author Topic: [SOLVED] Transparent form  (Read 702 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 647
[SOLVED] Transparent form
« on: May 12, 2026, 06:31:41 pm »
Hi, I've been wondering lately if it's possible to create a transparent form that supports components. I found an example on the forum with a transparent form and a PNG image of a rabbit, but it doesn't support components.
Best regards
« Last Edit: May 15, 2026, 04:07:21 pm by Pe3s »

Raskaton

  • New Member
  • *
  • Posts: 27
Re: Transparent form
« Reply #1 on: May 12, 2026, 07:19:35 pm »
Maybe an old idea: copy the image of the workarea (screenshot) under the form, and output it modified (blurred) in TImage.
Code: Pascal  [Select][+][-]
  1. Image1.Align := alClient;
  2. Form1.BorderStyle := bsNone;
  3.  
Just Z-index Image1 to back.
Taking screenshot (use OnCreate, before Form Show=True):
https://wiki.lazarus.freepascal.org/Developing_with_Graphics#Taking_a_screenshot_of_the_screen
or using package BGRABitmap:  TBGRABitmap.TakeScreenshot(MyFormRect)
But need some work after moving window/form.

Nicole

  • Hero Member
  • *****
  • Posts: 1324
Re: Transparent form
« Reply #2 on: May 12, 2026, 07:24:20 pm »
Yes, why not.

I use this for indicating me, if my batch is done: a savings pig.
A click puts the coin into the pig and as long as the software is busy the coin stays inside.

I used the "ImageList" component to import my pig.
From there I added it onto my form.

I attach you three screenshots:
The transparency shown in blue within the ImageList-Editor.
And how it looks at the form at design time and in the running application (the icon left to it has a white background).

I work with Lazarus 4.4. and a Win 7 VM.
About one year ago, I failed to do this within Linux Mint, what may have had many reasons.

mav

  • Jr. Member
  • **
  • Posts: 86
Re: Transparent form
« Reply #3 on: May 13, 2026, 12:30:19 am »
I hope this is what you're looking for.
The form moves by dragging the mouse from the image... Regards. I'm also sending the animated GIF component.

Pe3s

  • Hero Member
  • *****
  • Posts: 647
Re: Transparent form
« Reply #4 on: May 13, 2026, 08:47:26 am »
Everything's great, except how do I get rid of the purple color?

mav

  • Jr. Member
  • **
  • Posts: 86
Re: Transparent form
« Reply #5 on: May 13, 2026, 02:52:58 pm »
Example with sources?

Pe3s

  • Hero Member
  • *****
  • Posts: 647
Re: Transparent form
« Reply #6 on: May 13, 2026, 10:08:46 pm »
Example code

mav

  • Jr. Member
  • **
  • Posts: 86
Re: Transparent form
« Reply #7 on: May 14, 2026, 01:18:16 am »
Hi.. :) :)

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: Transparent form
« Reply #8 on: May 14, 2026, 06:10:05 am »
Everything's great, except how do I get rid of the purple color?
What OS are you using with what theming?

Pe3s

  • Hero Member
  • *****
  • Posts: 647
Re: Transparent form
« Reply #9 on: May 14, 2026, 07:34:57 am »
I'm using Windows 11. This solution would be perfect, but it doesn't render the components.

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: Transparent form
« Reply #10 on: May 14, 2026, 11:02:39 am »
I'm using Windows 11. This solution would be perfect, but it doesn't render the components.
You had an earlier example with the purple border.
Why not go back to that one and make your image not alpha blended?

For example (b.png attached which can be tweaked a little more):

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Image1.Picture.LoadFromFile('b.png');
  4.   Bmp := Image1.Picture.Bitmap;
  5.   if (Width <> Bmp.Width) or (Height <> Bmp.Height) then
  6.     SetBounds(Left, Top, Bmp.Width, Bmp.Height);
  7.   Color := clRed;
  8.   SetWindowLongPtr(Self.Handle, GWL_EXSTYLE, GetWindowLongPtr(Self.Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
  9.   SetLayeredWindowAttributes(Self.Handle, clRed, 0, LWA_COLORKEY);
  10. end;

Or do you really really want alpha blended images ??

Otherwise you would need to create regions for all your components to show them through the transparency.

Pe3s

  • Hero Member
  • *****
  • Posts: 647
Re: Transparent form
« Reply #11 on: May 15, 2026, 10:09:16 am »
I use files with transparency

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: Transparent form
« Reply #12 on: May 15, 2026, 10:13:08 am »
I use files with transparency
Transparency is different from alpha blending. See my version of your image in my previous post. It is transparent, but doesn't have alpha blending.

There is no problem with the given code if you just use normal transparency. The only problem arises when you begin using alpha blending (resulting in that purple border which is in fact the alpha blended parts of the image).

https://en.wikipedia.org/wiki/Alpha_compositing

So... just use normal transparency and there is no problem.

Pe3s

  • Hero Member
  • *****
  • Posts: 647
Re: Transparent form
« Reply #13 on: May 15, 2026, 04:07:05 pm »
Thank you for your help

 

TinyPortal © 2005-2018