Board index » delphi » tiled images on a panel

tiled images on a panel

i have a panel that i use as a toolbar, i would like to implement a tiled
background though... is this posible? and how
 

Re:tiled images on a panel


Quote
Stephan Johnson wrote:
> i have a panel that i use as a toolbar, i would like to implement a tiled
> background though... is this posible? and how

You'll need to create a descendant from TPanel where you override the Paint
method.  Inside the method is where you'll add you paint code.

Here is an example which uses the brush.

procedure TForm1.Button1Click(Sender: TObject);
var
  Bitmap: TBitmap;
begin
  Bitmap := TBitmap.Create;
  try
    Bitmap.LoadFromFile('C:\WINNT\Blue Lace 16.bmp');
    Form1.Canvas.Brush.Bitmap := Bitmap;
    Form1.Canvas.FillRect(Rect(0,0,300,300));
  finally
    Form1.Canvas.Brush.Bitmap := nil;
    Bitmap.Free;
  end;
end;

Here is one with tiling.

procedure TForm1.FormPaint(Sender: TObject);
var
  x, y: Integer;
begin
  y := 0;
  while y < Height do
  begin
    x := 0;
    while x < Width do
    begin
      Canvas.Draw(x, y, Bitmap);
      x := x + Bitmap.Width;
    end;
    y := y + Bitmap.Height;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Bitmap := TBitmap.Create;
  Bitmap.LoadFromFile('C:\WINNT\Blue Lace 16.bmp');
end;

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

Other Threads