PaintWhileLoad example for C++ Builder

This example causes the LEAD control to paint the image as it loads.

void __fastcall TForm1::Button3Click(TObject *Sender)
{
   float   HeightFactor, WidthFactor, HeightAllowed, WidthAllowed;
   int     ImageHeight, ImageWidth, BitmapHeight, BitmapWidth;

   Lead1->PaintWhileLoad = True;
   //Get information about the image so that we can size the control.
   Lead1->GetFileInfo("c:\\lead\\images\\image2.cmp", 0);
   //Set the variables used for preserving the aspect ratio.
   //Allow for a border of 1/8 of the form size.
   HeightFactor = Lead1->InfoHeight;
   WidthFactor = Lead1->InfoWidth;
   HeightAllowed = ClientHeight * 3/4;
   WidthAllowed = ClientWidth * 3/4;
   //Center the LEAD control on the form, preserving the aspect ratio.
   //Check to see if using the maximum width will make the image too tall.
   //Set the dimensions based on the result.
   if (((WidthAllowed * HeightFactor) / WidthFactor) < HeightAllowed )
   {
      Lead1->Left =  (ClientWidth / 8);
      Lead1->Width =  (WidthAllowed);
      Lead1->Height =  ((Lead1->Width * HeightFactor) / WidthFactor);
      Lead1->Top =  ((ClientHeight - Lead1->Height) / 2);
   }
   else
   {
      Lead1->Top =  (ClientHeight / 8);
      Lead1->Height =  (HeightAllowed);
      Lead1->Width =  ((Lead1->Height * WidthFactor) / HeightFactor);
      Lead1->Left =  ((ClientWidth - Lead1->Width) / 2);
   }
   //Set the image display sizes
   ImageHeight = Lead1->Height;
   ImageWidth = Lead1->Width;
   BitmapHeight = Lead1->InfoHeight;
   BitmapWidth = Lead1->InfoWidth;
   Lead1->SetSrcRect(0, 0, BitmapWidth, BitmapHeight);
   Lead1->SetSrcClipRect(0, 0, BitmapWidth, BitmapHeight);
   Lead1->SetDstRect(0, 0, ImageWidth, ImageHeight);
   Lead1->SetDstClipRect(0, 0, ImageWidth, ImageHeight);
   //Turn off the automatic adjustment of display rectangles
   Lead1->AutoSetRects = False;
   //Load the file
   Lead1->Load("c:\\lead\\images\\image2.cmp", 0, 0, 1);
 
   //Turn on the automatic adjustment of display rectangles for future use
   Lead1->AutoSetRects = True;
}