2004. november 12., péntek

Paint the form with a tiled bitmap


Problem/Question/Abstract:

Paint the form with a tiled bitmap

Answer:

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;

Nincsenek megjegyzések:

Megjegyzés küldése