Delphi:类似 FireFox 中的 AnimateWindow

发布于 2024-12-22 21:21:10 字数 309 浏览 2 评论 0原文

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

为了对面板进行动画处理,我使用:

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

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

但我希望其他控件能够在面板向下时平稳且同步地移动。

例如,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.

For example, FireFox uses this effect.

Can anybody suggest me something useful? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你如我软肋 2024-12-29 21:21:10

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;

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;
谁与争疯 2024-12-29 21:21:10

删除第二行

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

Delete the second line

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

and leave only

 AnimateWindow(Panel.Handle, 1000, aw_hide or AW_SLIDE OR AW_VER_POSITIVE);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文