Delphi:AnimateWindow就像在FireFox中一样

max*_*fax 5 delphi firefox animation window animatewindow

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

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

AnimateWindow(Panel.Handle, 1000, aw_hide or AW_SLIDE OR AW_VER_POSITIVE);
panel.Visible:=false;
Run Code Online (Sandbox Code Playgroud)

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

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

例如,FireFox使用此效果.

谁能建议我有用的东西?谢谢!

Ser*_*yuz 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;
Run Code Online (Sandbox Code Playgroud)

  • @Roro - 您不需要 OnTimer 中的 ProcessMessages 。一旦计时器事件处理程序返回,应用程序将继续处理消息。 (3认同)