1. Home
  2. Computing & Technology
  3. Delphi Programming

Paint a Form with a tiled bitmap image

By Zarko Gajic, About.com

Here's how to draw tiled bitmap image on a Form:

~~~~~~~~~~~~~~~~~~~~~~~~~
type
   TForm1 = class(TForm)
     procedure FormCreate(Sender: TObject) ;
     procedure FormPaint(Sender: TObject) ;
     procedure FormClose(Sender: TObject;
                         var Action: TCloseAction) ;
   private
   public
   end;

var
   Form1: TForm1;

   Bitmap: TBitmap;

...

procedure TForm1.FormCreate(Sender: TObject) ;
begin
   Bitmap := TBitmap.Create;
   Bitmap.LoadFromFile('C:\WINDOWS\cars.BMP') ;
end;

procedure TForm1.FormClose
   (Sender: TObject; var Action: TCloseAction) ;
begin
   Bitmap.Free;
end;

procedure TForm1.FormPaint(Sender: TObject) ;
var
   X, Y, W, H: LongInt;
begin
   with Bitmap do begin
     W := Width;
     H := Height;
   end;
   Y := 0;
   while Y < Height do begin
     X := 0;
     while X < Width do begin
       Canvas.Draw(X, Y, Bitmap) ;
       Inc(X, W) ;
     end;
     Inc(Y, H) ;
   end;
end;

~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Convert a BMP to a JPG
« Add a Check Box to a standard dialog box

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2001 Delphi Tips
  7. Paint a Form with a tiled bitmap image

©2009 About.com, a part of The New York Times Company.

All rights reserved.