Recent

Author Topic: how to change font.color of one single item of Tchecklistbox  (Read 412 times)

bbd666

  • New Member
  • *
  • Posts: 30
how to change font.color of one single item of Tchecklistbox
« on: February 07, 2025, 12:40:32 pm »
I guess the title is explicit enough.
I can change the font.color of all checkboxes of a Tchecklistbox, but I'd like to tune the checkboxes one by one with different font.colors.
Any help appreciated.

bbd666

  • New Member
  • *
  • Posts: 30
Re: how to change font.color of one single item of Tchecklistbox
« Reply #1 on: February 07, 2025, 12:49:02 pm »
this code can do the job for the font.color if style is set to lbOwnerDrawFixed, but no more checkboxes. with style set as lbStandard, nothing changed :

Code: Pascal  [Select][+][-]
  1. procedure TForm1.checkbox1DrawItem(Control: TWinControl; Index: Integer;
  2.   ARect: TRect; State: TOwnerDrawState);
  3. begin
  4.     with (Control as TCheckListBox).Canvas do
  5.   begin
  6.       FillRect(ARect);
  7.       if Index = 1 then
  8.         font.Color := clRed;
  9.        TextOut(ARect.Left, ARect.Top, (Control as TCheckListBox).Items[Index]);
  10.   end;
  11. end;  

Zvoni

  • Hero Member
  • *****
  • Posts: 2895
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

bbd666

  • New Member
  • *
  • Posts: 30
Re: how to change font.color of one single item of Tchecklistbox
« Reply #3 on: February 07, 2025, 01:43:51 pm »
ok thks,
but he built up a brand new Tchecklistbox class there, as much I understand.

Zvoni

  • Hero Member
  • *****
  • Posts: 2895
Re: how to change font.color of one single item of Tchecklistbox
« Reply #4 on: February 07, 2025, 02:13:05 pm »
ok thks,
but he built up a brand new Tchecklistbox class there, as much I understand.
How did you get to that conclusion? He's using a regular TCheckListBox.
Post #8 (Where my link points to)
he's using ThemeServices to draw the CheckBox (which is missing in your OwnerDraw-Version)
And he's using TextRect to draw his first Item of the CheckListBox in Bold.
And if you can set a font to bold for a single item, you can also change its color

EDIT: Attached Proof of concept
Note "LCLType" and "Themes" in Uses
« Last Edit: February 07, 2025, 02:34:26 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

bbd666

  • New Member
  • *
  • Posts: 30
Re: how to change font.color of one single item of Tchecklistbox
« Reply #5 on: February 07, 2025, 03:12:15 pm »
Great.
Many thks

 

TinyPortal © 2005-2018