The event OnItemBkgDraw
is definitely what you need to draw the background yourself.
But if I had to do this the background would never look really nice. So I would let somebody else do the drawing. Fortunately we can use the Fill.Fill
method which will generate a nice background which is compatible with the current item appearance and the overall look of the component.
This is your OnItemBkgDraw
handler:
uses AdvGDIP;
procedure TForm1.AdvSmoothListBox1ItemBkgDraw(Sender: TObject; Canvas: TCanvas; itemindex: Integer; itemRect: TRect;
var defaultdraw: Boolean);
var
g: TGPGraphics;
ItemAppearance: TAdvSmoothListBoxItemAppearance;
ir: TGPRectF;
begin
// Disable default background drawing behavior
DefaultDraw:= False;
// Create our own item appearance which will be responsible for drawing the background
// Note: The class needs an TAdvSmoothListBox owner, but we can't use ourselves as we would trigger an
// infinite update cycle - use a dummy list instead (can be created dynamically or
// just put it on your form being invisible)
ItemAppearance:= TAdvSmoothListBoxItemAppearance.Create(DummyOwner);
try
// Get the current item appearance which we want to adjust a little
ItemAppearance.Assign(AdvSmoothListBox1.ItemAppearance);
// Set nice colors for current item (you can use the itemindex parameter to see which item is currently being painted)
ItemAppearance.Fill.Color:= Random(High(TColor));
ItemAppearance.Fill.ColorTo:= Random(High(TColor));
// Now prepare the classes needed for drawing
g := TGPGraphics.Create(Canvas.Handle);
ir := MakeRect(itemrect.Left, itemrect.Top, itemrect.Right - itemrect.Left, itemrect.Bottom - itemrect.Top);
try
// And here it paints
ItemAppearance.Fill.Fill(g, ir);
finally
g.Free;
end;
finally
ItemAppearance.Free;
end;
// Done
end;