开发者

AnimateWindow Slide

开发者 https://www.devze.com 2022-12-21 05:12 出处:网络
I want my form slide down and back to position with slide animation, how to make correct AnimateWinows, if it real for sure ...

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


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;


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消