窗体全透明但窗体上的控件不透明
相关资料:
https://www.iteye.com/blog/paulfzm-1835285
实例1:
1 unit Unit1; 2 3 interface 4 5 uses 6 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 7 Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls; 8 9 type 10 TForm1 = class(TForm) 11 Button1: TButton; 12 ListBox1: TListBox; 13 Memo1: TMemo; 14 Edit1: TEdit; 15 ProgressBar1: TProgressBar; 16 TrackBar1: TTrackBar; 17 procedure Button1Click(Sender: TObject); 18 private 19 { Private declarations } 20 public 21 { Public declarations } 22 end; 23 24 var 25 Form1: TForm1; 26 27 implementation 28 29 {$R *.dfm} 30 31 procedure TForm1.Button1Click(Sender: TObject); 32 Var 33 frmRegion, tempRegion: HRGN; 34 I: Integer; 35 Arect: TRect; 36 Begin 37 frmRegion := 0; 38 For I:= 0 To ControlCount - 1 Do 39 Begin 40 aRect := Controls[I].BoundsRect; 41 OffsetRect(aRect, clientorigin.x - left, clientorigin.y - top); 42 tempRegion := CreateRectRgnIndirect(aRect); 43 If frmRegion = 0 Then 44 frmRegion := tempRegion 45 Else 46 Begin 47 CombineRgn(frmRegion, frmRegion, tempRegion, RGN_OR); 48 DeleteObject(tempRegion); 49 End; 50 End; 51 tempregion := 52 CreateRectRgn( 0, 0, Width, 53 GetSystemMetrics(SM_CYCAPTION)+ 54 GetSystemMetrics(SM_CYSIZEFRAME)+ 55 GetSystemMetrics(SM_CYMENU) * Ord(Menu <> Nil)); 56 57 CombineRgn(frmRegion, frmRegion, tempRegion, RGN_OR); 58 DeleteObject(tempRegion); 59 SetWindowRgn(handle, frmRegion, true); 60 end; 61 62 end.
实例2:
1 unit Unit1; 2 3 interface 4 5 uses 6 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 7 Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; 8 9 type 10 TForm1 = class(TForm) 11 Button1: TButton; 12 Edit1: TEdit; 13 procedure FormCreate(Sender: TObject); 14 private 15 { Private declarations } 16 public 17 { Public declarations } 18 end; 19 20 var 21 Form1: TForm1; 22 23 implementation 24 25 {$R *.dfm} 26 27 procedure TForm1.FormCreate(Sender: TObject); 28 begin 29 form1.color:=clred; 30 form1.TransparentColorValue:=clred; 31 form1.TransparentColor:=true; 32 end; 33 34 end.
作者:疯狂Delphi
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
欢迎关注我,一起进步!扫描下方二维码即可加我