动画窗口幻灯片

发布于 2024-08-23 03:44:34 字数 460 浏览 7 评论 0原文

我希望我的表单向下滑动并返回到带有幻灯片动画的位置,如何制作正确的 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 :)

I want my form slide down and back to position with slide animation, how to make correct AnimateWinows, if it real for sure ...

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

to moderators : here is no mutters Builder or Delphi :)

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

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

发布评论

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

评论(3

我也只是我 2024-08-30 03:44:34

如果您有兴趣自己控制动画,这里是我们为实现此目的而编写的代码示例。它看起来和工作都很棒。我们在主窗体上的 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;

If you are interested in controlling the animation yourself, here is a sample of code we wrote to accomplish that. It looks and works great. We are sliding Tform1 from the right to the left within a TPanel control on the main form. We ensure that Self.Parent and DoubleBuffered gets set correctly in MyCreate. ShiftLeft and then ShiftRight do the work. We ran into a problem for certain users where the Self.Top was being shifted so we are making sure that Self.Top := 0 with each iteration and when fully shifted. That solved all of the weird issues we were seeing.

Hope this helps!

{
  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;
删除→记忆 2024-08-30 03:44:34

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

相反,您应该做的是循环地不断升高或降低窗口,直到达到新的所需高度。

That's not what AnimateWindow is for. That function hides or shows a window using some animation. Your window is already visible, and you want it to stay visible, so AnimateWindow is not for you.

What you should do instead is make your window successively taller or shorter in a loop until you reach the new desired height.

绅刃 2024-08-30 03:44:34

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

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

Check the following link for an answer and a cool demo program.

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

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