窗体

procedure TForm1.FormCreate(Sender: TObject);
var
   FullRgn, ClientRgn, ButtonRgn: THandle;
   LeftMargin,TopMargin:Integer;
   Margin, X, Y: Integer;
   i:integer;
begin
     Margin := (Width - ClientWidth) div 2;
     FullRgn := CreateRectRgn(0, 0, Width, Height);
     LeftMargin := Margin;
     TopMargin := Height - ClientHeight - Margin;
     ClientRgn := CreateRectRgn(LeftMargin, TopMargin, LeftMargin + ClientWidth, TopMargin + ClientHeight);
     CombineRgn(FullRgn, FullRgn, ClientRgn, RGN_DIFF);
     for i:= 0 to ComponentCount-1 do
         begin
         if not (Components[i] is TWinControl) then continue;
         if (Components[i] as TWinControl).Parent<>self then continue;
         X := LeftMargin + (Components[i] as TWinControl).Left;
         Y := TopMargin + (Components[i] as TWinControl).Top;
         ButtonRgn := CreateRectRgn(X, Y, X + (Components[i] as TWinControl).Width, Y + (Components[i] as TWinControl).Height);
         CombineRgn(FullRgn, FullRgn, ButtonRgn, RGN_OR);
         end;
     SetWindowRgn(Handle, FullRgn, True);
end;

会漏掉image控件 比较无奈

procedure TForm1.FormCreate(Sender: TObject);
var
  I: Integer;
  FullRgn,
  ClientRgn,
  ControlRgn: THandle;
  Margin,
  MarginX,
  MarginY,
  X,
  Y: Integer;
  W,H,S :Integer;
  bX,bY :Integer;
  c     :TColor;
begin
  Margin := (Width - ClientWidth) div 2;
  FullRgn := CreateRectRgn(0, 0, Width, Height); 
  MarginX := Margin; 
  MarginY := Height - ClientHeight - Margin;
  ClientRgn := CreateRectRgn(MarginX, MarginY, MarginX + ClientWidth, MarginY + ClientHeight);
  CombineRgn(FullRgn, FullRgn, ClientRgn, RGN_DIFF); 
  DeleteObject(ClientRgn); 
  for I:=0 to ControlCount-1 do
  begin
    X := MarginX + Controls[I].Left; 
    Y := MarginY + Controls[I].Top; 
    W:=Controls[I].Width;
    H:=Controls[I].Height;
{} 
    if controls[i] is timage then begin
      with controls[i] as tImage do begin
        c:=Picture.Bitmap.Canvas.Pixels[0,0];
        for bX:=0 to Picture.Bitmap.Width-1 do begin 
          for bY:=0 to Picture.Bitmap.Height-1 do begin
            if Picture.Bitmap.Canvas.Pixels[bX,bY]<>c then begin
              ControlRgn := CreateRectRgn(X+bX, Y+bY, X + bX+1, Y + bY+1); 
              CombineRgn(FullRgn, FullRgn, ControlRgn, RGN_OR);
              DeleteObject(ControlRgn); 
            end;
          end;
        end; 
      end; 
    end else
{}
    if controls[i] is tShape then begin 
      if W < H then S := W else S := H; 
      if (Controls[i] as tshape).Shape in [stSquare, stRoundSquare, stCircle] then
      begin 
        Inc(X, (W - S) div 2); 
        Inc(Y, (H - S) div 2); 
        W := S;
        H := S; 
      end;
      Inc(W); Inc(H); Inc(S); 
      case (controls[i] as tshape).Shape of
        stRectangle, stSquare: 
          ControlRgn := CreateRectRgn(X, Y, X + W, Y + H); 
        stRoundRect, stRoundSquare: 
          ControlRgn := CreateRoundRectRgn(X, Y, X + W, Y + H, S div 4, S div 4);
        stCircle, stEllipse: 
          ControlRgn:=CreateEllipticRgn(X, Y, X + W, Y + H); 
      else 
        ControlRgn := CreateRectRgn(X, Y, X + W, Y + H);
      end;
      CombineRgn(FullRgn, FullRgn, ControlRgn, RGN_OR);
      DeleteObject(ControlRgn); 
    end else
{} 
    begin
      ControlRgn := CreateRectRgn(X, Y, X + W, Y + H); 
      CombineRgn(FullRgn, FullRgn, ControlRgn, RGN_OR);
      DeleteObject(ControlRgn); 
    end;
  end;
  SetWindowRgn(Handle, FullRgn, True);
  DeleteObject(FullRgn);
end;

安全绿色无公害·······


全透明窗体(效果比较好)
uses里加上ExtCtrls
procedure tform1.setformtransparent;
var
  I: Integer;
  FullRgn,
  ClientRgn,
  ControlRgn: THandle;
  Margin, 
  MarginX, 
  MarginY, 
  X, 
  Y: Integer;
  W,H,S :Integer; 
  bX,bY :Integer; 
  c     :TColor; 
begin
  Margin := (Width - ClientWidth) div 2; 
  FullRgn := CreateRectRgn(0, 0, Width, Height); 
  MarginX := Margin; 
  MarginY := Height - ClientHeight - Margin;
  ClientRgn := CreateRectRgn(MarginX, MarginY, MarginX + ClientWidth, MarginY + ClientHeight); 
  CombineRgn(FullRgn, FullRgn, ClientRgn, RGN_DIFF); 
  DeleteObject(ClientRgn); 
  for I:=0 to ControlCount-1 do
  begin 
    X := MarginX + Controls[I].Left; 
    Y := MarginY + Controls[I].Top; 
    W:=Controls[I].Width;
    H:=Controls[I].Height; 
{} 
    if controls[i] is timage then begin
      with controls[i] as tImage do begin
        c:=Picture.Bitmap.Canvas.Pixels[0,0];
        for bX:=0 to Picture.Bitmap.Width-1 do begin 
          for bY:=0 to Picture.Bitmap.Height-1 do begin 
            if Picture.Bitmap.Canvas.Pixels[bX,bY]<>c then begin
              ControlRgn := CreateRectRgn(X+bX, Y+bY, X + bX+1, Y + bY+1); 
              CombineRgn(FullRgn, FullRgn, ControlRgn, RGN_OR); 
              DeleteObject(ControlRgn); 
            end;
          end; 
        end; 
      end; 
    end else
{} 
    if controls[i] is tShape then begin 
      if W < H then S := W else S := H; 
      if (Controls[i] as tshape).Shape in [stSquare, stRoundSquare, stCircle] then
      begin 
        Inc(X, (W - S) div 2); 
        Inc(Y, (H - S) div 2); 
        W := S;
        H := S; 
      end; 
      Inc(W); Inc(H); Inc(S); 
      case (controls[i] as tshape).Shape of
        stRectangle, stSquare: 
          ControlRgn := CreateRectRgn(X, Y, X + W, Y + H); 
        stRoundRect, stRoundSquare: 
          ControlRgn := CreateRoundRectRgn(X, Y, X + W, Y + H, S div 4, S div 4);
        stCircle, stEllipse: 
          ControlRgn:=CreateEllipticRgn(X, Y, X + W, Y + H); 
      else 
        ControlRgn := CreateRectRgn(X, Y, X + W, Y + H);
      end; 
      CombineRgn(FullRgn, FullRgn, ControlRgn, RGN_OR); 
      DeleteObject(ControlRgn); 
    end else
{} 
    begin 
      ControlRgn := CreateRectRgn(X, Y, X + W, Y + H); 
      CombineRgn(FullRgn, FullRgn, ControlRgn, RGN_OR);
      DeleteObject(ControlRgn); 
    end; 
  end; 
  SetWindowRgn(Handle, FullRgn, True);
  DeleteObject(FullRgn);
end;
procedure TForm1.FormResize(Sender: TObject);
begin
        setformtransparent;
end;

//rock
//转载请保留此信息


原稿


 

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值