procedure TForm1.FormClick(Sender: TObject);
var
R : HRgn;
begin
if IsRound then
begin
SetWindowRgn(Handle,0,True);
DeleteObject(R);
IsRound := False;
end
else
begin
R := CreateEllipticRgn(-15,-15,Width+15,Height+15);
SetWindowRgn(Handle,R,True);
IsRound := True;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
IsRound := False;
end;
end.
////////////////////////////////////////////
四四方方的窗体也会变形,利用win32 API函数setwindowrgn就可以将窗口定义为任何形状,以下是将窗口定义为园角矩形的例子:
procedure TPortForm.FormCreate(Sender: Tobject);
var hr :thandle;
begin
hr:=createroundrectrgn(0,0,width,height,20,20);//定义园角矩形(win API函数)
setwindowrgn(handle,hr,true);
//设置园角窗口
end;
为了使该窗口更好,应在onResize事件处理程序放相同的代码。
/////////////////////////////////////
用汉字做窗体形状
procedure TForm1.FormCreate(Sender: TObject);
var
rgn:HRGN;
begin
begin
Path(Canvas.Handle);
SetBkMode( Canvas.Handle, TRANSPARENT );
Canvas.Font.Name:= '宋体';
Canvas.Font.Size:=100;
Canvas.TextOut( 20, 20, '漂亮吗?');//用"漂亮吗?"作为form的形状
EndPath(Canvas.Handle);
rgn:= PathToRegion(Canvas.Handle);
SetWindowRgn( Handle, rgn, true );
end;