Close a form animated

Close a form animated

var
  tutup: Boolean;
  i: Integer;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  reg1, reg2: hrgn;
begin
  if tutup = True then
  begin
    i := i + 10;
    reg1 := CreateRoundRectRgn(0 + i, 0 + i, Width - i, Height - i, 20, 20);
    SetWindowRgn(Handle, reg1, True);
  end;

  if i >= Width then
  begin
    tutup := False;
    i := 1;
  end;

  if tutup = False then
  begin
    i := i + 10;
    reg1 := CreateRectRgn(0, 0, (Width div 2) - i, Height);
    reg2 := CreateRectRgn((Width div 2) + i, 0, Width, Height);
    CombineRgn(reg1, reg1, reg2, rgn_or);
    SetWindowRgn(Handle, reg1, True);
    if i >= Width div 2 then
    begin
      tutup := True;
      i := 1;
    end;
  end;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
  reg1: hrgn;
begin
  i := 1;
  timer1.Enabled := True;
  if MessageDlg('Exit now ?',
    mtConfirmation, [mbYes, mbNo], 0) = mrYes then
    CanClose := True
  else
  begin
    CanClose := False;
    timer1.Enabled := False;
    reg1 := CreateRoundRectRgn(0, 0, Width, Height, 0, 0);
    SetWindowRgn(Handle, reg1, True);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  tutup := True;
  timer1.Enabled := False;
end;