Board index » delphi » Form Tiled Background - How?

Form Tiled Background - How?

I'm sure I've seen this somewhere, but how can one set a form background to
be a tiled bitmap?

I found a third-party VCL on uk.torry.net to do this but its awfuly 'clunky'

Thanks,

Roy.
r...@flightlab.liv.ac.uk

 

Re:Form Tiled Background - How?


"Roy Coates" <r...@camaro.org.uk> skrev i en meddelelse
news:99df68$abq$1@news.liv.ac.uk...

Quote
> I'm sure I've seen this somewhere, but how can one set a form background
to
> be a tiled bitmap?

From an old test program of mine:

type
  TTestForm = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { Private declarations }
    procedure ShowBitmap;
  public
    { Public declarations }
  end;

var
  TestForm: TTestForm;
  Bitmap: TBitmap;

implementation

{$R *.DFM}
{$R BMP.RES}

procedure TTestForm.FormCreate(Sender: TObject);
begin
  Bitmap := TBitmap.Create;
  Bitmap.LoadFromResourceName(Hinstance, 'facesmil');
end;

procedure TTestForm.FormDestroy(Sender: TObject);
begin
  Bitmap.Free;
end;

procedure TTestForm.FormPaint(Sender: TObject);
begin
  ShowBitmap;
end;

procedure TTestForm.ShowBitmap;
var
  x, y, xinc, yinc: Integer;
begin
  xinc := Bitmap.Width + 2;
  yinc := Bitmap.Height + 2;
  if TestForm.Canvas.Brush.Bitmap = nil then
  TestForm.Canvas.Brush.Bitmap := Bitmap;
  for y := 0 to Trunc(ClientHeight / yinc) do
    for x := 0 to Trunc(ClientWidth / xinc) do
      TestForm.Canvas.Draw(x * xinc, y * yinc, Bitmap);
  TestForm.Canvas.Brush.Bitmap := nil;
end;

Finn Tolderlund

Re:Form Tiled Background - How?


Many thanks :)

Roy.

"Finn Tolderlund" <XnospamYfinn.tolderlu...@Ymobilixnet.dkXnospamY> wrote in
message news:%Asu6.62$yW1.54881335@news.mobilixnet.dk...

Quote

> "Roy Coates" <r...@camaro.org.uk> skrev i en meddelelse
> news:99df68$abq$1@news.liv.ac.uk...
> > I'm sure I've seen this somewhere, but how can one set a form background
> to
> > be a tiled bitmap?

> From an old test program of mine:

> type
>   TTestForm = class(TForm)
>     procedure FormCreate(Sender: TObject);
>     procedure FormDestroy(Sender: TObject);
>     procedure FormPaint(Sender: TObject);
>   private
>     { Private declarations }
>     procedure ShowBitmap;
>   public
>     { Public declarations }
>   end;

> var
>   TestForm: TTestForm;
>   Bitmap: TBitmap;

> implementation

> {$R *.DFM}
> {$R BMP.RES}

> procedure TTestForm.FormCreate(Sender: TObject);
> begin
>   Bitmap := TBitmap.Create;
>   Bitmap.LoadFromResourceName(Hinstance, 'facesmil');
> end;

> procedure TTestForm.FormDestroy(Sender: TObject);
> begin
>   Bitmap.Free;
> end;

> procedure TTestForm.FormPaint(Sender: TObject);
> begin
>   ShowBitmap;
> end;

> procedure TTestForm.ShowBitmap;
> var
>   x, y, xinc, yinc: Integer;
> begin
>   xinc := Bitmap.Width + 2;
>   yinc := Bitmap.Height + 2;
>   if TestForm.Canvas.Brush.Bitmap = nil then
>   TestForm.Canvas.Brush.Bitmap := Bitmap;
>   for y := 0 to Trunc(ClientHeight / yinc) do
>     for x := 0 to Trunc(ClientWidth / xinc) do
>       TestForm.Canvas.Draw(x * xinc, y * yinc, Bitmap);
>   TestForm.Canvas.Brush.Bitmap := nil;
> end;

> Finn Tolderlund

Other Threads