Forms are boring solid objects. But you can make it fun in many ways. One of them is transparency. Here’s how…
Quick Tutorial
Create a new Application project (Project -> New Project -> Application -> OK).
Set the color of the form to Red ($000002EE
). Create buttons and stuff that you want to test with.
Add windows
in the uses
clause:
1 | uses |
Below the uses
clause enter these lines:
1 | const |
Below the line implementation
add these procedures:
1 | procedure SetTranslucent(ThehWnd: Longint; Color: Longint; nTrans: Integer); |
Double click the form and enter the following code. (Note: You will have to change the value of transparency value to the form’s color, or the color that you want to be transparent.)
1 | procedure TForm1.FormCreate(Sender: TObject); |
Run it
Did you entered them correctly? Let’s test it out. Press F9 (or Run -> Run).
Are you satisfied? Your form is look-through.
The above code uses windows
unit and Windows API so it is not cross platform.
Concept
The procedures let the Windows’ window manager say that “Where you find x color make it transparent.” Remember, what color you use as the transparency variable value will be transparent, no matter in which component the color is. (If you change the red color then set it like: transparency := $000002EE;
in the form’s on create event) It could be even images We have used red. So if red is on an image, that will be transparent too. That’s a disadvantage, but it is a cool effect.
If you want better options, then use form regions. You can define in a better way the shape of the form.
You can also have translucency effect, which is widely used in splash screens.
Ref:
http://www.lazarus.freepascal.org/index.php/topic,8488.0.html
Downloads
You can download the source code for the tutorial project and executable/EXE files from the links below: