Making Transparent Form

At Delphi, we can create a transparent form. To create a transparent form, can follow the steps in the example below.

Example: create a Form with a Label and a trackbar.

procedure SetTransparent(hWnd: longint; value: Byte);
Var iExStyle: Integer;
begin
 iExStyle := GetWindowLong(hWnd, GWL_EXSTYLE);
 if value < 255 then begin
  iExStyle := iExStyle Or WS_EX_LAYERED;
  SetWindowLong(hWnd, GWL_EXSTYLE, iExStyle);
  SetLayeredWindowAttributes(hWnd, 0, value, LWA_ALPHA);
 end else begin
  iExStyle := iExStyle xor WS_EX_LAYERED;
  SetWindowLong(hWnd, GWL_EXSTYLE, iExStyle);
 end;
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
 SetTransparent(Handle, TrackBar1.Position);
end;

No comments:

Post a Comment