delphidabbler / delphi-tips

A bunch of Delphi language tips migrated from the DelphiDabbler.com website, plus others.
https://tips.delphidabbler.com
31 stars 11 forks source link

New tip: Animated roll down form #83

Open delphidabbler opened 1 year ago

delphidabbler commented 1 year ago

Possible new tip from extra/Topelina Tips.odt


formRolling

Creating a roll up form (with animation).

Here's a handy piece of code that will create a roll-down and roll-up effect for a form object when a user right-clicks its title bar:

type
   TForm1 = class(TForm)
   private
    fOldClientHeight: Integer;
    procedure WMNCRButtonDown(var Msg: TWMNCRButtonDown) ; message WM_NCRBUTTONDOWN;
   public
   end;

var
   Form1: TForm1;

implementation
{$R *.dfm}

procedure TForm1.WMNCRButtonDown(var Msg: TWMNCRButtonDown) ;
var
   h : integer;
begin
   if (Msg.HitTest = HTCAPTION) then
   begin
     if (ClientHeight = 0) then
     begin
       for h := 0 to fOldClientHeight do ClientHeight := h;
       Application.ProcessMessages;
     end
     else
     begin
       fOldClientHeight := ClientHeight;
       for h := fOldClientHeight downto 0 do ClientHeight := h;
       Application.ProcessMessages;
     end;
   end;
end;

Contributed by: topellina riccardo.faiella@alice.it