Delphi:AnimateWindow就像在FireFox中一样

时间:2011-12-24 14:54:57

标签: delphi firefox animation window animatewindow

我有一个面板(底部对齐)和一些控件(客户端对齐)。

为我使用的面板设置动画:

AnimateWindow(Panel.Handle, 1000, aw_hide or AW_SLIDE OR AW_VER_POSITIVE);
panel.Visible:=false;

在我的情况下,面板平滑地隐藏,然后只有其他控件占用它的空间。

但我希望其他控件能够顺利地与面板同时移动。

例如,FireFox使用此效果。

有人能建议我有用吗?谢谢!

2 个答案:

答案 0 :(得分:2)

AnimateWindow是一个同步函数,在动画结束前不会返回。这意味着在dwTime参数中指定的时间内,没有对齐代码将运行,并且'alClient'对齐的控件将保持静止,直到动画结束。

我建议改用计时器。举个例子:

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;

答案 1 :(得分:-1)

删除第二行

AnimateWindow(Panel.Handle, 1000, aw_hide or AW_SLIDE OR AW_VER_POSITIVE);
panel.Visible:=false;

并且只留下

 AnimateWindow(Panel.Handle, 1000, aw_hide or AW_SLIDE OR AW_VER_POSITIVE);
相关问题