在你打开新窗体的事件中加入以下代码:(假设新窗体名为form2) …… var i:integer; …… form2.show; with form2 do begin width := 1; height := 1; for i := 1 to 100 do begin width := i; height := i; left := 400 - i; top := 400 - i; end; end; 这段代码执行后,能达到你所说的要求,但由于时间关系,效果没有调好,自己慢慢去调试吧。 希望各位高手多多指正,提出更好的办法。
我的解决方案(经过实践): 思路: 在 FormShow的时候,不断的改变 Form 窗口的 区域Rgn来实现类司蚂蚁的效果; 而不是改变窗口的大小(Height,Width)。 具体实现: 1.在 FormShow 的时候,给本 Form 发送一个自定义消息 const WM_MUSIC_NOTIFY = WM_USER + 1004; 2.在消息处理过程中调用 mscShowMinToMax( self, 1 ); 3.我的函数集: interface procedure mscShowMinToMax( frmSender: TForm; iStyle: integer ); overload; procedure mscShowMinToMax( frmSender: TForm; MinRc: Trect ); overload; { mscStyleToRect 将风格代码转换成Rect } function mscStyleToRect( frmSender: TForm; iStyle: integer ): TRect;implementation procedure mscShowMinToMax( frmSender: TForm; iStyle: integer ); var MinRc: Trect; begin MinRc := mscStyleToRect( frmSender, iStyle ); mscShowMinToMax( frmSender, MinRc ); end; procedure mscShowMinToMax( frmSender: TForm; MinRc: Trect ); var rc: TRect; Region: HRGN; begin with frmSender do begin rc := MinRc; while ( rc.Left > 0 ) or ( rc.Top > 0 ) or ( rc.Right < Width ) or ( rc.Bottom < Height ) do begin if rc.Left > 0 then Dec( rc.Left ); if rc.Top > 0 then Dec( rc.Top ); if rc.Right < Width then Inc( rc.Right ); if rc.Bottom < Height then Inc( rc.Bottom ); Region := CreateRectRgn( rc.Left, rc.Top, rc.Right, rc.Bottom ); SetWindowRgn( Handle, Region, true ); DeleteObject( Region ); end; end; end; function mscStyleToRect( frmSender: TForm; iStyle: integer ): TRect; const MAX_STYLE = 13; // ( 0 .. 12 ) begin if ( iStyle < 1 ) or ( iStyle > 12 ) then iStyle := 1; with frmSender do begin case iStyle of 0,1: begin Result.Left := Width div 2 - ( Width div 2 div 8 ); Result.Top := Height div 2 - ( Height div 2 div 8 ); Result.Right := Width div 2 + ( Width div 2 div 8 ); Result.Bottom := Height div 2 + ( Height div 2 div 8 ); end; 2: Result := Rect( 0, 0, Width, 0 ); // up to bottom 3: Result := Rect( 0, 0, 0, Height ); // left to right 4: Result := Rect( 0, Height, Width, Height ); // bottom to up 5: Result := Rect( Width, 0, Width, Height ); // right to left 6: Result := Rect( Width, 0, 0, 0 ); 7: Result := Rect( 0, 0, 0, 0 ); // left top Corner to right bottom corner 8: Result := Rect( 0, Height, 0, Height ); // left bottom to right top 9: Result := Rect( Width, Height, Width, Height ); // right bottom to left top 10: Result := Rect( 0, Height, 0, 0 ); 11: Result := Rect( Width, Height, 0, Height ); 12: Result := Rect( Width, 0, Width, 0 ); end; end; end;
……
var i:integer;
……
form2.show;
with form2 do
begin
width := 1;
height := 1;
for i := 1 to 100 do
begin
width := i;
height := i;
left := 400 - i;
top := 400 - i;
end;
end;
这段代码执行后,能达到你所说的要求,但由于时间关系,效果没有调好,自己慢慢去调试吧。
希望各位高手多多指正,提出更好的办法。
思路:
在 FormShow的时候,不断的改变 Form 窗口的 区域Rgn来实现类司蚂蚁的效果;
而不是改变窗口的大小(Height,Width)。
具体实现:
1.在 FormShow 的时候,给本 Form 发送一个自定义消息
const
WM_MUSIC_NOTIFY = WM_USER + 1004;
2.在消息处理过程中调用
mscShowMinToMax( self, 1 );
3.我的函数集:
interface
procedure mscShowMinToMax( frmSender: TForm; iStyle: integer ); overload;
procedure mscShowMinToMax( frmSender: TForm; MinRc: Trect ); overload;
{ mscStyleToRect 将风格代码转换成Rect }
function mscStyleToRect( frmSender: TForm; iStyle: integer ): TRect;implementation
procedure mscShowMinToMax( frmSender: TForm; iStyle: integer );
var
MinRc: Trect;
begin
MinRc := mscStyleToRect( frmSender, iStyle );
mscShowMinToMax( frmSender, MinRc );
end;
procedure mscShowMinToMax( frmSender: TForm; MinRc: Trect );
var
rc: TRect;
Region: HRGN;
begin
with frmSender do
begin
rc := MinRc;
while ( rc.Left > 0 ) or ( rc.Top > 0 )
or ( rc.Right < Width ) or ( rc.Bottom < Height ) do
begin
if rc.Left > 0 then
Dec( rc.Left );
if rc.Top > 0 then
Dec( rc.Top );
if rc.Right < Width then
Inc( rc.Right );
if rc.Bottom < Height then
Inc( rc.Bottom );
Region := CreateRectRgn( rc.Left, rc.Top,
rc.Right, rc.Bottom );
SetWindowRgn( Handle, Region, true );
DeleteObject( Region );
end;
end;
end;
function mscStyleToRect( frmSender: TForm; iStyle: integer ): TRect;
const
MAX_STYLE = 13; // ( 0 .. 12 )
begin
if ( iStyle < 1 ) or ( iStyle > 12 ) then
iStyle := 1;
with frmSender do
begin
case iStyle of
0,1:
begin
Result.Left := Width div 2 - ( Width div 2 div 8 );
Result.Top := Height div 2 - ( Height div 2 div 8 );
Result.Right := Width div 2 + ( Width div 2 div 8 );
Result.Bottom := Height div 2 + ( Height div 2 div 8 );
end;
2: Result := Rect( 0, 0, Width, 0 ); // up to bottom
3: Result := Rect( 0, 0, 0, Height ); // left to right
4: Result := Rect( 0, Height, Width, Height ); // bottom to up
5: Result := Rect( Width, 0, Width, Height ); // right to left
6: Result := Rect( Width, 0, 0, 0 );
7: Result := Rect( 0, 0, 0, 0 ); // left top Corner to right bottom corner
8: Result := Rect( 0, Height, 0, Height ); // left bottom to right top
9: Result := Rect( Width, Height, Width, Height ); // right bottom to left top
10: Result := Rect( 0, Height, 0, 0 );
11: Result := Rect( Width, Height, 0, Height );
12: Result := Rect( Width, 0, Width, 0 );
end;
end;
end;
在窗体的OnShow事件中加入:
AnimateWindow(handle,ADELAY,aw_center);
倒是用一个API函数有用:
AnimateWindow(Handle,300,AW_CENTER);
但这样窗本本身有显示出来而不是显示窗体轮廓。
但是,我的代码那么多!艾!太笨了!
不如人家一个句子搞定!省时间,省精力!
不过话得说回来,我的方法可以有多种风格显示。
加一个参数,以免丢失焦点;
AnimateWindow( Handle, 100, AW_CENTER OR AW_ACTIVATE);
我觉得可以把窗体隐藏
取得窗体相关属性,比如位置、大小等
然后呢,在将要显示窗体的区域自己画出要做的效果来
最后显示窗体不知道这样是否可以
明天结束问题。
那个API WIN98支持。95不支持。
AnimateWindow98支持吗?
我用的是2000,没有98试验
听说不支持啊