Hola.
Un ejemplo que te permite seleccionar el color del texto de cada item de un
TCheckListBox:
Código Delphi
[-]
...
type
TForm1 = class(TForm)
CheckListBox1: TCheckListBox;
ColorDialog1: TColorDialog;
btnChangeColor: TButton;
procedure FormCreate(Sender: TObject);
procedure CheckListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure btnChangeColorClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation {$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
for i := 1 to 5 do
CheckListBox1.Items.AddObject('TEXTO ' + IntToStr(i), TObject(clBlack)); CheckListBox1.Style := lbOwnerDrawFixed;
end;
procedure TForm1.CheckListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
clb: TCheckListBox;
begin
clb := CheckListbox1;
clb.Canvas.FillRect(Rect);
clb.Canvas.Font.Color := TColor(clb.Items.Objects[Index]);
clb.Canvas.TextOut(Rect.Left, Rect.Top, clb.Items[Index]);
end;
procedure TForm1.btnChangeColorClick(Sender: TObject);
var
clb: TCheckListBox;
begin
clb := CheckListBox1;
if (clb.ItemIndex <> -1) and ColorDialog1.Execute then
begin
clb.Items.Objects[clb.itemIndex] := TObject(ColorDialog1.Color); clb.Invalidate;
end;
end;
end.
Resultado:
Saludos