Board index » delphi » Scrollbox background image

Scrollbox background image

Does anyone know how to create a tiled background on a scrollbox canvas,
exactely like the tiled background used on html pages.
The problem should be solved if a scrollbox background cold be transparent,
then I could place the image on the form canvas.

Thanks in advance
Paul van Andel

 

Re:Scrollbox background image


"Paul van Andel" <p.van.andelNOS...@hccnet.nl> wrote in message
news:9cq5v4$kdn$1@news.hccnet.nl...

Quote
> Does anyone know how to create a tiled background on a scrollbox canvas,
> exactely like the tiled background used on html pages.
> The problem should be solved if a scrollbox background cold be
transparent,
> then I could place the image on the form canvas.

I tried to handle the WM_PAINT and WM_NCPAINT messages of the TSCrollBar but
I couldn't get it to work properly. Finally, I wrote my own control which is
not quite finished right now.

OT:
I also created some other skin-aware controls but I don't have much time to
develop them further. I was wandering if people would be interested in them
if I put them in the open  source community. I don't know if such project
already exists, and all I could find on Torry was some commercial packages
with skin-controls. So far I have TSkinPanel, TSkinScrollBar, THotImage.
What do you people think?

Thanks,
Smola

Re:Scrollbox background image


Make another component:

unit TileScrollBox;

interface

uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs;

type TTileScrollBox = class(TScrollBox)
 private
  FBitmap: TBitmap;
    procedure SetBitmap(const Value: TBitmap);
    procedure OnBitmapChange(Sender: TObject);
    procedure WMPaint(var message: TWMPaint); message WM_PAINT;
 protected
    procedure Paint; virtual;
 public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
 published
    property Bitmap: TBitmap read FBitmap write SetBitmap;
end;

procedure Register;

implementation

procedure Register;
begin
 RegisterComponents('My comps', [TTileScrollBox]);
end;

constructor TTileScrollBox.Create(AOwner: TComponent);
begin
 inherited Create(AOwner);
 FBitmap:= TBitmap.Create;
 FBitmap.OnChange:= OnBitmapChange;
end;

destructor TTileScrollBox.Destroy;
begin
 FBitmap.Free;
 inherited Destroy;
end;

procedure TTileScrollBox.OnBitmapChange(Sender: TObject);
begin
 Invalidate;
end;

procedure TTileScrollBox.SetBitmap(const Value: TBitmap);
begin
 FBitmap.Assign(Value);
end;

procedure TTileScrollBox.Paint;
 var X, Y, W, H: LongInt; Rect: TRect; DC: HDC;
begin
 Rect:= GetClientRect;
 W:= FBitmap.Width;
 H:= FBitmap.Height;
 Y:= Rect.Top;

 if (H > 0) and (W > 0) then
  begin
    DC:= GetDC(Self.Handle);
    while Y < Height do
     begin
       X:= Rect.Left;
       while X < Width do
        begin
          BitBlt(DC, X, Y, W, H, FBitmap.Canvas.Handle, 0, 0, SrcCopy);
          Inc(X, W);
          end;
       Inc(Y, H);
       end;
     end;
end;

procedure TTileScrollBox.WMPaint(var message: TWMPaint);
begin
 inherited;
 Paint;
end;

end.

"Paul van Andel" <p.van.andelNOS...@hccnet.nl> wrote in message
news:9cq5v4$kdn$1@news.hccnet.nl...

Quote
> Does anyone know how to create a tiled background on a scrollbox canvas,
> exactely like the tiled background used on html pages.
> The problem should be solved if a scrollbox background cold be
transparent,
> then I could place the image on the form canvas.

> Thanks in advance
> Paul van Andel

Re:Scrollbox background image


Quote
> Make another component:

Thanks, this seems the work for panels and buttons, but unfortunately not
for a TImage, this will not show at all.
I already have something working, but I'm curious why a TImage is not
visible when I use this TileScrollBox component.

Paul.

Quote
> unit TileScrollBox;

> interface

> uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
> Dialogs;

> type TTileScrollBox = class(TScrollBox)
>  private
>   FBitmap: TBitmap;
>     procedure SetBitmap(const Value: TBitmap);
>     procedure OnBitmapChange(Sender: TObject);
>     procedure WMPaint(var message: TWMPaint); message WM_PAINT;
>  protected
>     procedure Paint; virtual;
>  public
>     constructor Create(AOwner: TComponent); override;
>     destructor Destroy; override;
>  published
>     property Bitmap: TBitmap read FBitmap write SetBitmap;
> end;

> procedure Register;

> implementation

> procedure Register;
> begin
>  RegisterComponents('My comps', [TTileScrollBox]);
> end;

> constructor TTileScrollBox.Create(AOwner: TComponent);
> begin
>  inherited Create(AOwner);
>  FBitmap:= TBitmap.Create;
>  FBitmap.OnChange:= OnBitmapChange;
> end;

> destructor TTileScrollBox.Destroy;
> begin
>  FBitmap.Free;
>  inherited Destroy;
> end;

> procedure TTileScrollBox.OnBitmapChange(Sender: TObject);
> begin
>  Invalidate;
> end;

> procedure TTileScrollBox.SetBitmap(const Value: TBitmap);
> begin
>  FBitmap.Assign(Value);
> end;

> procedure TTileScrollBox.Paint;
>  var X, Y, W, H: LongInt; Rect: TRect; DC: HDC;
> begin
>  Rect:= GetClientRect;
>  W:= FBitmap.Width;
>  H:= FBitmap.Height;
>  Y:= Rect.Top;

>  if (H > 0) and (W > 0) then
>   begin
>     DC:= GetDC(Self.Handle);
>     while Y < Height do
>      begin
>        X:= Rect.Left;
>        while X < Width do
>         begin
>           BitBlt(DC, X, Y, W, H, FBitmap.Canvas.Handle, 0, 0, SrcCopy);
>           Inc(X, W);
>           end;
>        Inc(Y, H);
>        end;
>      end;
> end;

> procedure TTileScrollBox.WMPaint(var message: TWMPaint);
> begin
>  inherited;
>  Paint;
> end;

> end.

Other Threads