Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   TCheckListBox: Colores individuales (https://www.clubdelphi.com/foros/showthread.php?t=85572)

Angel.Matilla 02-04-2014 11:02:50

TCheckListBox: Colores individuales
 
¿Se podría hacr en un TCheckListBox que cada un de los ítemes tuviera un color de fondo diferente?

Neftali [Germán.Estévez] 02-04-2014 13:13:49

Cita:

Empezado por Angel.Matilla (Mensaje 474707)
¿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...

Angel.Matilla 02-04-2014 13:14:34

Gracias por la ayuda.


La franja horaria es GMT +2. Ahora son las 04:25:07.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi