Ver Mensaje Individual
  #2  
Antiguo 02-04-2014
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 19.441
Reputación: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Cita:
Empezado por Angel.Matilla Ver Mensaje
¿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;

  // Fondo
  CheckListBox1.Canvas.FillRect(Rect);
  // Texto
  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...
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita