title: Smooth transition between two Forms in VCL
body: <p>I have been playing around for few hours with this but I cannot make it work. I have an application made of two Forms, and I want to switch from one form to another. I want this switch to be "smooth" (ie blending effect).</p>
  
  <p>I came up with this solution which works partially : using the AnimateWindow function in the ShowForm() method. This works fine when I switch from Form1 to Form2. But switching back to Form1 does not work. Form1 is painted "behind" Form2 and when Form2 hides, the transition is already done.</p>
  
  <p>Below is the very simple code for Form1:</p>
  
  <pre><code>#include &lt;vcl.h&gt;
  #pragma hdrstop
  
  #include "main_form.h"
  #include "child_form.h"
  //---------------------------------------------------------------------------
  #pragma package(smart_init)
  #pragma resource "*.dfm"
  TForm1 *Form1;
  //---------------------------------------------------------------------------
  __fastcall TForm1::TForm1(TComponent* Owner)
      : TForm(Owner)
  {
  }
  //---------------------------------------------------------------------------
  void __fastcall TForm1::Button1Click(TObject *Sender)
  {
      Form2 -&gt; Show();
      Form1 -&gt; Hide();
  }
  //---------------------------------------------------------------------------
  void __fastcall TForm1::FormShow(TObject *Sender)
  {
      const int speed = 1000;
      AnimateWindow(Handle, speed, AW_BLEND);
  }
  </code></pre>
  
  <p>and here the code for Form2:</p>
  
  <pre><code>#include &lt;vcl.h&gt;
  #pragma hdrstop
  
  #include "child_form.h"
  #include "main_form.h"
  //---------------------------------------------------------------------------
  #pragma package(smart_init)
  #pragma resource "*.dfm"
  TForm2 *Form2;
  //---------------------------------------------------------------------------
  __fastcall TForm2::TForm2(TComponent* Owner)
      : TForm(Owner)
  {
  }
  //---------------------------------------------------------------------------
  void __fastcall TForm2::Button1Click(TObject *Sender)
  {
      Form1 -&gt; Show();
      Form2 -&gt; Hide();
  
  }
  //---------------------------------------------------------------------------
  void __fastcall TForm2::FormShow(TObject *Sender)
  {
      const int speed = 1000;
      AnimateWindow(Handle, speed, AW_BLEND);
  }
  </code></pre>
  
  <p>I tried to invert the <code>Form1-&gt;Show()</code>and <code>Form2-&gt;Hide()</code>statements in the code for Form2, to force hiding Form2 before painting Form1, but it does not work either: Form2 is hidden, then nothing is shown during animation time, and then Form1 is displayed all of a sudden.</p>
  
  <p>Any idea?</p>
  
  <p>Thanks.</p>