Author: Tomas Rutkauskas
How to change the color of the selection in a TCheckListBox
Answer:
If you want to change the color of the selection so that it's always the Color
property, this code will work:
1 2 procedure TForm1.CheckListBox1DrawItem(Control: TWinControl;
3 Index: Integer; Rect: TRect; State: TOwnerDrawState);
4 begin5 with Control as TCheckListBox do6 begin7 { Use the default colors regardless of selection status }8 Canvas.Font.Color := Font.Color;
9 Canvas.Brush.Color := Color;
10 { Erase everything there at the moment }11 Canvas.FillRect(Rect);
12 { Draw the text }13 Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]);
14 end;
15 end;