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!

有帮助吗?

解决方案

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;

其他提示

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top