본문 바로가기
Delphi, RadStudio

[개발/델파이] delphi TPanel or TForm 을 투명하게

by SB리치퍼슨 2015. 7. 3.

delphi TPanel or TForm 을 투명하게



procedure TForm1.Button1Click(Sender: TObject);
begin
ClearPanel(TPanel(panel1));//전달인수를 폼으로 하면 폼또한 투명효과를 줄 수 있다. 
end;

procedure TForm1.ClearPanel(var panel : TPanel);
var  I : Integer;
    FullRgn, ClientRgn, ControlRgn : THandle;
    Margin, MarginX, MarginY, X, Y : Integer; 
begin 
    Margin := (panel.Width - panel.ClientWidth) div 2; 
    FullRgn := CreateRectRgn(0, 0, panel.Width, panel.Height); 
    MarginX := Margin; 
    MarginY := panel.Height - panel.ClientHeight - Margin; 
    ClientRgn := CreateRectRgn(MarginX, MarginY, MarginX + panel.ClientWidth, 
                                                 MarginY + panel.ClientHeight); 
    CombineRgn(FullRgn, FullRgn, ClientRgn, RGN_DIFF); 
    for I:=0 to panel.ControlCount-1 do begin 
        X := MarginX + panel.Controls[I].Left; 
        Y := MarginY + panel.Controls[I].Top; 
        ControlRgn := CreateRectRgn(X, Y, X + panel.Controls[I].Width, 
                                          Y + panel.Controls[I].Height); 
        CombineRgn(FullRgn, FullRgn, ControlRgn, RGN_OR); 
    end; 
    SetWindowRgn(panel.Handle, FullRgn, True); 
end;


반응형

댓글