Cita:
Empezado por Angel.Matilla
¿Se podría hacr en un TCheckListBox que cada un de los ítemes tuviera un color de fondo diferente?
|
La forma de hacerlo es pintando de forma "manual" los items de la lista
Coloca la propiedad Style a lbOwnedDrawFixed
En el procedimiento OnDrawItem del CheckListBox coloca el siguiente código:
Código Delphi
[-]
procedure Tt.CheckListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
if (index = 0) then begin
CheckListBox1.Canvas.Brush.Color := clYellow;
end
else if (index = 1) then begin
CheckListBox1.Canvas.Brush.Color := clInfoBk;
end
else if (index = 2) then begin
CheckListBox1.Canvas.Brush.Color := clMoneyGreen;
end
else if (index = 3) then begin
CheckListBox1.Canvas.Brush.Color := clBtnFace;
end;
CheckListBox1.Canvas.FillRect(Rect);
CheckListBox1.Canvas.TextOut(Rect.Left, Rect.Top, CheckListBox1.Items[index]);
end;
Deberás añadir cambios para el color del texto y tener en cuenta cuando el elemeno está seleciconado (parámetro State), pero este es un principio...