Searching around for a means of alternating background colour in a TListBox gave me lots of examples, and I ended up with this modification ...
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
begin
with (Control as TListBox).Canvas do begin
Brush.Style:=bsSolid;
if odSelected in State then
begin
Brush.Color:=clBlue;
Font.Color:=clWhite;
end
else
if Index=0 then
begin
Brush.Color:=clRed;
Font.Color:=clYellow;
Font.Style:=[fsbold,fsItalic];
end
else
if Index mod 2=1 then
begin
Brush.Color:=clSkyBlue;
end
else
begin
Brush.Color:=clMoneyGreen;
end;
FillRect(ARect);
Brush.Style:=bsClear;
TextOut(ARect.Left, ARect.Top, (Control as TListBox).Items[Index]);
end;
end;
But the above only draws active items.
The problem is that my ListBox starts off empty and gradually fills from the top down, hence the Red background for item 0.
How do I draw empty items, taking into account that the bottom display item may not be fully visible (ie cut off half height).
Also I need to take into account that the list box will have a scroll bar and the last few items may only be visible.