線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1909
推到 Plurk!
推到 Facebook!

如何將From視窗的底色便成透明

 
領航天使
站長


發表:12216
回覆:4186
積分:4084
註冊:2001-07-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-06-18 21:40:05 IP:192.168.xxx.xxx 未訂閱
以下程式可以將Form1的底色便成透空, 請拉一From1/Panel1/Button1/Button2 設定From1的OnCreate/OnDestory/OnReSize事件 設定Button1/Button2的OnClick事件 執行後按Button1可以透空,再按一次還原喔! 可以做為程式特殊效果運用!
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;    type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    { Private declarations }
    procedure DoVisible;
    procedure DoInvisible;
  public
    { Public declarations }
  end;    var
  Form1: TForm1;      FullRgn, ClientRgn, CtlRgn: THandle;    implementation    {$R *.DFM}    procedure TForm1.DoInvisible;
var
  AControl: TControl;
  A, Margin, X, Y, CtlX, CtlY: Integer;
begin
  Margin := (Width - ClientWidth) div 2;
  FullRgn := CreateRectRgn(0, 0, Width, Height);
  X := Margin;
  Y := Height - ClientHeight - Margin;
  ClientRgn := CreateRectRgn(X, Y, X   ClientWidth, Y   ClientHeight);
  CombineRgn(FullRgn, FullRgn, ClientRgn, RGN_DIFF);
  for A := 0 to ControlCount - 1 do begin
    AControl := Controls[A];
    if (AControl is TWinControl) or (AControl is TGraphicControl)
      then with AControl do begin
        if Visible then begin
          CtlX := X   Left;
          CtlY := Y   Top;
          CtlRgn := CreateRectRgn(CtlX, CtlY, CtlX   Width, CtlY   Height);
          CombineRgn(FullRgn, FullRgn, CtlRgn, RGN_OR);
        end;
      end;
  end;
  SetWindowRgn(Handle, FullRgn, TRUE);
end;    procedure TForm1.FormDestroy(Sender: TObject);
begin
  DeleteObject(ClientRgn);
  DeleteObject(FullRgn);
  DeleteObject(CtlRgn);
end;    procedure TForm1.DoVisible;
begin
  FullRgn := CreateRectRgn(0, 0, Width, Height);
  CombineRgn(FullRgn, FullRgn, FullRgn, RGN_COPY);
  SetWindowRgn(Handle, FullRgn, TRUE);
end;    procedure TForm1.FormCreate(Sender: TObject);
begin
  DoInvisible;
end;    procedure TForm1.Button1Click(Sender: TObject);
begin
  if Button1.Caption = 'Show Form' then begin
    DoVisible;
    Button1.Caption := 'Hide Form';
  end
  else begin
    DoInvisible;
    Button1.Caption := 'Show Form';
  end;
end;    procedure TForm1.Button2Click(Sender: TObject);
begin
  Application.Terminate;
end;    procedure TForm1.FormResize(Sender: TObject);
begin
  if Button1.Caption = 'Show Form' then
    DoInvisible
  else
    DoVisible;
end;    end.
~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~
附加檔案:00018906_unit1.pas
系統時間:2024-11-23 3:57:00
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!