Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

For example, FireFox uses this effect.

Can anybody suggest me something useful? Thanks!

like image 892
maxfax Avatar asked Nov 14 '22 12:11

maxfax


1 Answers

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;
like image 135
Sertac Akyuz Avatar answered Jan 11 '23 02:01

Sertac Akyuz