半透明窗體在各類WinForm編程中常見,下面這段代碼是用Delphi實現了一個簡單但效果不錯的透明窗口,可以看到窗口下面的內容,代碼比較簡單,後附運行效果。
01
unit
Unit1;
02
interface
03
uses
04
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
05
Dialogs, StdCtrls, Buttons, ExtCtrls, TeEngine, SerIEs, TeeProcs, Chart,
06
jpeg;
07
type
08
TForm1 =
class
(TForm)
09
BitBtn1: TBitBtn;
10
BitBtn2: TBitBtn;
11
procedure
FormCreate(Sender: TObject);
12
procedure
BitBtn1Click(Sender: TObject);
13
private
14
{ Private declarations }
15
public
16
{ Public declarations }
17
end
;
18
var
19
Form1: TForm1;
20
implementation
21
{$R *.dfm}
22
procedure
TForm1
.
FormCreate(Sender: TObject);
23
begin
24
form1
.
Color := clHotLight;
25
form1
.
TransparentColorValue := clHotLight;
26
form1
.
TransparentColor :=
True
;
27
brush
.
Style := bsclear;
28
end
;
29
procedure
TForm1
.
BitBtn1Click(Sender: TObject);
30
begin
31
close;
32
end
;
33
end
.
Delphi簡單實現半透明窗口,代碼編譯截圖:窗體是在代碼上邊顯示的。