AnimateWindow幻灯片

时间:2010-02-27 06:49:08

标签: delphi c++builder vcl

我希望我的表单向下滑动并返回到幻灯片动画的位置,如何制作正确的AnimateWinows,如果它确实是真的......

void __fastcall TUsers::BitBtn1Click(TObject *Sender)
{
if (!pressed)
{
        Height=700;
        //AnimateWindow(Handle, 500, AW_CENTER | AW_SLIDE | AW_VER_POSITIVE);
        pressed=true;
}
else
{
        pressed=false;
        //AnimateWindow(Handle, 500, AW_CENTER | AW_SLIDE | AW_VER_NEGATIVE);
        Height=425;
}
}

主持人:这里没有嘟嘟Builder或Delphi:)

3 个答案:

答案 0 :(得分:3)

如果您有兴趣自己控制动画,下面是我们为实现这一目标而编写的代码示例。它看起来很棒。我们在主窗体上的TPanel控件中从右向左滑动Tform1。我们确保在MyCreate中正确设置Self.Parent和DoubleBuffered。 ShiftLeft然后ShiftRight完成工作。我们遇到了Self.Top被移位的某些用户的问题所以我们确保每次迭代和完全移位时Self.Top:= 0。这解决了我们所看到的所有奇怪问题。

希望这有帮助!

{
  TForm1.MyCreate
  ---------------------------------------------------------------------------
}
constructor TForm1.MyCreate(AOwner: TComponent);
var
  OwnerControl: TWinControl;
begin
  inherited Create(AOwner);

  if Owner is TWinControl then
  begin
    OwnerControl := Owner as TWinControl;
    Self.Parent := OwnerControl;
  end;

  Self.Visible := false;
  Self.DoubleBuffered := true;
  Self.BorderStyle := bsNone;

end;

{
  TForm1.ShiftLeft
  ---------------------------------------------------------------------------
}
procedure TForm1.ShiftLeft;
var
  TicksStart: int64;
  InitLeftValue: integer;
  StartLeftValue: integer;
  NewLeftValue: integer;
  LeftValueDif: integer;
  RemainingTicks: int64;

begin
  Self.Top := 0;
  Self.Height := Self.Parent.ClientHeight;
  Self.Width := Self.Parent.ClientWidth;

  InitLeftValue := Self.Parent.Left;
  StartLeftValue := Self.Parent.Left + Self.Parent.ClientWidth;
  LeftValueDif := StartLeftValue - InitLeftValue;

  Self.Left := StartLeftValue;
  Self.Visible := true;

  TicksStart := GetTickCount();
  RemainingTicks := FadeTime;

  while RemainingTicks > 0 do
  begin
    NewLeftValue := (LeftValueDif * RemainingTicks) div FadeTime;
    Self.Left := Max(InitLeftValue, NewLeftValue);
    Self.Parent.Repaint;
    Self.Top := 0;
    Self.Repaint;

    RemainingTicks := FadeTime - int64(GetTickCount - TicksStart);
  end;

  if Self.Left > InitLeftValue then
    Self.Left := InitLeftValue;

  Self.Parent.Repaint;
  Self.Top := 0;
  Self.Repaint;
end;

{
  TForm1.ShiftRight
  ---------------------------------------------------------------------------
}
procedure TForm1.ShiftRight;
var
  TicksStart: int64;
  StartLeftValue: integer;
  EndLeftValue: integer;
  NewLeftValue: integer;
  LeftValueDif: integer;
  RemainingTicks: int64;

begin
  Self.Top := 0;
  StartLeftValue := Self.Left;
  EndLeftValue := Self.Left + Self.Width;
  LeftValueDif := EndLeftValue - StartLeftValue;

  TicksStart := GetTickCount();
  RemainingTicks := FadeTime;

  while RemainingTicks > 0 do
  begin
    NewLeftValue := (LeftValueDif * (FadeTime - RemainingTicks)) div FadeTime;
    Self.Left := Max(StartLeftValue, NewLeftValue);
    Self.Parent.Repaint;
    Self.Top := 0;
    Self.Repaint;

    RemainingTicks := FadeTime - int64(GetTickCount - TicksStart);
  end;

  if Self.Left < EndLeftValue then
    Self.Left := EndLeftValue;

  Self.Parent.Repaint;
  Self.Top := 0;
  Self.Repaint;
end;

答案 1 :(得分:1)

这不是AnimateWindow的用途。该函数使用某些动画隐藏或显示窗口。您的窗口已经显示,并且您希望它保持可见,因此AnimateWindow不适合您。

你应该做的是让你的窗户在一个循环中连续变高或变短,直到你达到新的理想高度。

答案 2 :(得分:1)

检查以下链接以获得答案和一个很酷的演示程序。

http://delphi.about.com/od/delphi-tips-2011/qt/hide-slide-fade-away-controls-delphi-form.htm