I did search how to do this, must be using the wrong search term because oddly didn't find a way.
I want to draw the alternate lines Grey and the other lines White and account for highlighted line. I have the following
procedure TfrmDLGOptions.lbDictDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
var
ListBox: TListBox;
Canvs: TCanvas;
begin
ListBox := Control as TListBox;
Canvs := ListBox.Canvas;
if Index mod 2 = 0 then
begin
Canvs.Brush.Color := clSilver;
Canvs.FillRect(ARect);
canvs.Pen.color := clWindowText;
end else
begin
Canvs.Brush.Color := clWindow;
Canvs.FillRect(ARect);
canvs.Pen.color := clWindowText;
end;
if ListBox.ItemIndex = Index then
begin
Canvs.Brush.Color := clHighlight;
canvs.FillRect(ARect);
canvs.Pen.color := clHighlightText;
end;
Canvs.TextOut(ARect.Left, ARect.Top, ListBox.Items[Index]);
end;
It works - ish, when selecting a line it highlights it okay, then for some reason on the 'white' lines it will then leave the background as the highlight color and not clWindowText.
Any help would be gratefully appreciated, I just don't see why it's not working! As I said I did do a search, my google-fu must not be that strong.
CJ