Delphi:类似于 FireFox 中的 AnimateWindow [英] Delphi: AnimateWindow like in FireFox
问题描述
我有一个面板(底部对齐)和一些控件(客户端对齐).
I have a panel (bottom aligned) and some controls (client aligned).
为我使用的面板设置动画:
To animate the panel I use:
AnimateWindow(Panel.Handle, 1000, aw_hide or AW_SLIDE OR AW_VER_POSITIVE);
panel.Visible:=false;
在我的情况下,面板平滑地隐藏,然后其他控件才会占用它的空间.
In my case the panel smoothly hides and only then other controls take it's space.
但我希望其他控件在面板向下的同时平稳移动.
But I want that other controls move smoothly and simultaneously with the panel down.
例如,FireFox 使用这种效果.
For example, FireFox uses this effect.
有人能给我推荐一些有用的东西吗?谢谢!
Can anybody suggest me something useful? Thanks!
推荐答案
AnimateWindow
是一个同步函数,动画结束前不会返回.这意味着在 dwTime
参数指定的时间内,不会运行任何对齐代码,并且您的alClient"对齐控件将保持静止,直到动画完成.
AnimateWindow
is a synchronous function, it will not return until the animation finishes. That means during the time specified in dwTime
parameter, no alignment code will run and your 'alClient' aligned controls will stay still until the animation finishes.
我建议改用计时器.举个例子:
I'd suggest to use a timer instead. Just an example:
type
TForm1 = class(TForm)
..
private
FPanelHeight: Integer;
FPanelVisible: Boolean;
..
procedure TForm1.FormCreate(Sender: TObject);
begin
FPanelHeight := Panel1.Height;
Timer1.Enabled := False;
Timer1.Interval := 10;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled := True;
FPanelVisible := not FPanelVisible;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
const
Diff: array [Boolean] of Integer = (-1, 1);
begin
Panel1.Height := Panel1.Height - Diff[FPanelVisible];
Panel1.Visible := Panel1.Height > 0;
Timer1.Enabled := (Panel1.Height > 0) and (Panel1.Height < FPanelHeight);
end;
这篇关于Delphi:类似于 FireFox 中的 AnimateWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!