Delphi:如何像FireFox一样使用AnimateWindow?

5

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

为了给面板加上动画效果,我使用以下方法:

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

在我的情况下,面板平稳地隐藏,然后其他控件才占用它的空间。
但我希望其他控件与面板一起平滑移动。
例如,FireFox 使用此效果。
有人可以给我提供一些有用的建议吗?谢谢!
2个回答

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;

你忘记在timer1timer中使用application.proccessmessage。 - AsepRoro
3
在OnTimer中不需要使用ProcessMessages。一旦定时器事件处理程序返回,应用程序将继续处理消息。 - Sertac Akyuz
哦,太好了,这对我来说是个很好的输入,因为我以前从不知道,谢谢。 - AsepRoro

-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);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接