DelphiFAQ Home Search:

Paint the form with a tiled bitmap

 

comments1 comments. Current rating: 5 stars (1 votes). Leave comments and/ or rate it.

You may use this code to accomplish it:

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
    destructor Destroy; override;
  end;

var
  Form1: TForm1;
  Bitmap: TBitmap;

..

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

destructor TForm.Destroy;
begin
  inherited;
  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;
You don't like the formatting? Check out SourceCoder then!

Comments:

2008-05-20, 10:01:14
anonymous  
rating
good piece of code :) i have used it in a open source game i am creating
called psychocat google pschocatdemo for more info on it if your interested
in using tiles for your program.
i use the following make a big form ie 10000 by 10000 pixels for a RTS board

then use this to move it only when there is no other activity. (using ttimer
gives poor results) so use this instead

procedure tform1.scroller2(direction: integer);
var
msg : TMsg;

begin
repeat
if m_wait_mode then
begin
if not GetMessage(msg ,0 ,0 ,0 ) then
break;

TranslateMessage(msg );
DispatchMessage (msg );
break;
end
else
if PeekMessage(msg ,0 ,0 ,0 ,PM_REMOVE ) then
begin
TranslateMessage(msg );

if msg.message = WM_QUIT then
break;

DispatchMessage(msg );

end
else
begin

if direction = moveRight then
scrollerRight;
if direction = moveLeft then
scrollerLeft;
if direction = moveDown then
scrollerDown;
if direction = moveUp then
scrollerUp;

end;
until false;

//result:=msg.wParam;

end;

procedure tform1.scrollerUp;

begin
if form1.top < 0 then //> -(form1.height-screen.height) then
begin
form1.Top := form1.Top + scrollinc;
panel1.Top := panel1.Top - scrollinc;
//label1.Caption := inttostr(form1.Left);
end
else
application.Terminate;
end; // other scrollers work the same etc just minus to top to scroll down

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.