I have read some questions about this in the last week or so, on stackoverflow.
My requirement is more or less the same.
I need to put a semi-transparent layer on top my form, but this form may have several other components: Lists, Edits, Labels, Images ,etc
I need this semi-transparent layer to be on top of all that.
The idea is to fade areas of the form that the use those not, or cannot access in that moment.
I use Delphi 2007.
Thanks
Put a white rectangle over the background image and make that semi-transparent. Put these both on the same layer and lock it and draw on a new layer above. Set the transparency of the image by selecting it then use the transparency tool, use uniform and the desired transparency level. Here ya go. I hadn't look at the file.
Put a white rectangle over the background image and make that semi-transparent. Put these both on the same layer and lock it and draw on a new layer above. Set the transparency of the image by selecting it then use the transparency tool, use uniform and the desired transparency level.
There may be times though when you want only a small part of one layer to be transparent or semi-transparent. The trick, my friends, is that you need to firstly select the part of the layer that you want to adjust the transparency of and then make your adjustment.
In the middle payer add a rectangle covering the entire bitmap. Color it white, make that layer have transparency. Lock the bitmap and middle layer. Trace away. Put a white rectangle over the background image and make that semi-transparent. Put these both on the same layer and lock it and draw on a new layer above.
Create a new VCL project. Add a few sample buttons and other controls to the main form. Create a new form, set AlphaBlend
to true
and AlphaBlendValue
to 128
. Perhaps Color = clSkyBlue
will suffice? Then add the following procedure to your main form:
procedure TForm1.UpdateShadow;
var
pnt: TPoint;
rgn, rgnCtrl: HRGN;
i: Integer;
begin
if not Assigned(Form2) then Exit;
Form2.Show;
pnt := ClientToScreen(Point(0, 0));
Form2.SetBounds(pnt.X, pnt.Y, ClientWidth, ClientHeight);
rgn := CreateRectRgn(0, 0, Form2.Width, Form2.Height);
for i := 0 to ControlCount - 1 do
if Controls[i].Tag = 1 then
begin
if not (Controls[i] is TWinControl) then Continue;
with Controls[i] do
rgnCtrl := CreateRectRgn(Left, Top, Left+Width, Top+Height);
CombineRgn(rgn, rgn, rgnCtrl, RGN_DIFF);
DeleteObject(rgnCtrl);
end;
SetWindowRgn(Form2.Handle, rgn, true);
DeleteObject(rgn);
end;
and call this on resize,
procedure TForm1.FormResize(Sender: TObject);
begin
UpdateShadow;
end;
and form move:
procedure TForm1.WMMove(var Message: TWMMove);
begin
inherited;
UpdateShadow;
end;
Finally, set the Tag
to 1
on the controls (on your main form) that are to be accessible.
(source: rejbrand.se)
Hint: You might also wish to set the Cursor
of the 'shadow form' to crNo
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With