如何用delphi5做一个任意形状的窗体(40分)

  • 主题发起人 主题发起人 seaerwang
  • 开始时间 开始时间
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;

 
http://www.chinaasp.com/delphi/faq/showfaq.asp?id=1646
 
用现成的控件,如:vcl_extrapack
 

unit Unit1;

interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure CreateParams(var Params: TCreateParams);
override;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.DFM}
procedure TForm1.CreateParams(var Params: TCreateParams);

begin

inherited CreateParams(Params);

{Remove caption and border}
Params.Style := Params.Style or ws_popup xor ws_dlgframe;

end;


procedure TForm1.FormCreate(Sender: TObject);
var
FormRgn: hRgn;

begin

{clear form }
Form1.Brush.Style := bsSolid;
//bsclear;

{make form round}
GetWindowRgn(Form1.Handle, FormRgn);

{ delete the old object?}
DeleteObject(FormRgn);

{ make the form rectangular }
Form1.Height := 500;

Form1.Width := Form1.Height;

{ create the round form }
FormRgn := CreateRoundRectRgn(1, 1, Form1.Width - 1,
Form1.height - 1, Form1.width, Form1.height);

{ set the new round window }
SetWindowRgn(Form1.Handle, FormRgn, TRUE);

end;

end.

别人的,呵呵,不好意思。
 
1stclass 有相应的控件和实例,需要的话,我可以Email给你一个
 
to polygon
能给我么?charliecy@china.com
 
my e-mail:seaerwang@citiz.net
or
seaerwang@jstel.net
 
To polygon:
也给我发一个吧!谢谢
email :hankerjiang@263.net
 
http://mantousoft.51.net
有11stclass空间包和那个不规则窗口离子.
 
接受答案了.
 
后退
顶部