Board index » delphi » Tile Bitmap onto background of listbox?

Tile Bitmap onto background of listbox?

Does anyone know how to tile a bitmap onto the background of a Listbox?  I
assume this needs to be done in the OnPaint event handler but I'm quite
sure what steps are involved.  I'm looking for a way of doing this with the
minimum amount of flicker when the list is scrolled.

Source code appreciated but not neccessary.  Just and idea of the steps
involved would be appreciated.

Regards
--
Stan Stern
No Compromise

 

Re:Tile Bitmap onto background of listbox?


On 2 Apr 1998 15:17:02 GMT, "Stan Stern" <be...@monaco.mc> wrote:

Quote
>Does anyone know how to tile a bitmap onto the background of a Listbox?  I
>assume this needs to be done in the OnPaint event handler but I'm quite
>sure what steps are involved.  I'm looking for a way of doing this with the
>minimum amount of flicker when the list is scrolled.

You could try doing this when processing WM_ERASEBKGND messages.
You'll need to create a TListBox descendant, and process the message.

---
Yorai Aminov
El-On Software Systems
http://ourworld.compuserve.com/homepages/yaminov

Re:Tile Bitmap onto background of listbox?


I've done it catching the OnDrawItem event: it gives you the rect of the
canvas and you only have to set the ListBox style in lbOwnerDrawFixed.
Then you draw in the canvas what you want. You only have to check the
last item in the list, to fill the rest of the control if it's not full
of lines.

Here is an example of the code I used in a program, it painted the back
of LlistaImatges with the image in ImatgeFons:

procedure TFormLamines.LlistaImatgesDrawItem(Control: TWinControl;Index:
Integer; Rect: TRect; State: TOwnerDrawState);
var
   OldStyle : TBrushStyle;
   R : TRect;
begin
   if Index = LlistaImatges.Items.Count - 1 then
   begin
     Rect.Bottom := LlistaImatges.Height;
   end;

   R.Top := (Index * LlistaImatges.ItemHeight) mod
FormTools.ImatgeFons.Picture.Height;
   R.Bottom := R.Top + Rect.Bottom - Rect.Top;
   if R.Bottom > FormTools.ImatgeFons.Picture.Height then
   begin
     R.Top := 0;
     R.Bottom := R.Top + Rect.Bottom - Rect.Top;
   end;
   R.Left := Rect.Left;
   R.Right := Rect.Right;
   LlistaImatges.Canvas.CopyRect( Rect,
FormTools.ImatgeFons.Picture.Bitmap.Canvas, R );

   OldStyle := LlistaImatges.Canvas.Brush.Style;
   LlistaImatges.Canvas.Brush.Style := bsClear;
   LlistaImatges.Canvas.Font.Color := clBlack;
   LlistaImatges.Canvas.TextOut( Rect.Left + 3, Rect.Top + 1,
LlistaImatges.Items[ Index ] );
   LlistaImatges.Canvas.Font.Color := clWhite;
   LlistaImatges.Canvas.TextOut( Rect.Left + 2, Rect.Top,
LlistaImatges.Items[ Index ] );
   LlistaImatges.Canvas.Brush.Style := OldStyle;

end;

Quote
Stan Stern wrote:
> Does anyone know how to tile a bitmap onto the background of a
> Listbox?  I
> assume this needs to be done in the OnPaint event handler but I'm
> quite
> sure what steps are involved.  I'm looking for a way of doing this
> with the
> minimum amount of flicker when the list is scrolled.

> Source code appreciated but not neccessary.  Just and idea of the
> steps
> involved would be appreciated.

> Regards
> --
> Stan Stern
> No Compromise

--
--------------------------------
 JORDI******** ******** ********
    ******** ******** **********
   ***         ***           ***
  ******     ***    *********
 ***      *************    ***
***      ************* 1998 ***
--------------------------------

Other Threads