Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ListCheckBox

59 views
Skip to first unread message

Test

unread,
Oct 12, 1999, 3:00:00 AM10/12/99
to
I am using a component TListCheckBox, and I want to change the color of the
font (or highlight the caption) when an item is checked. It seems
impossible to reach such items properties, individually ?
Tell me I am wrong ...

Ian Stuart

unread,
Oct 13, 1999, 3:00:00 AM10/13/99
to
I think you mean TCheckListBox in which case you have to set its Style to
lbOwnerDrawFixed and do some drawing in the OnDrawItem event.

Ian

Peter Below (TeamB)

unread,
Oct 13, 1999, 3:00:00 AM10/13/99
to
In article <7u0krq$lp...@forums.borland.com>, Test wrote:
> I am using a component TListCheckBox, and I want to change the color of the
> font (or highlight the caption) when an item is checked. It seems
> impossible to reach such items properties, individually ?
>

There are no individual checkbox controls in the list, they are all fakes.
The checklistbox is a owner-drawn listbox internally, unfortunately coded in
a way that makes changing the way it draws somewhat difficult. Here is a
little project that shows how to change the text background color depending
on the items state. It has one major drawback: the checkbox is not drawn on
the selected color but always on the controls Color as background. The only
way to modify the drawing of the checkbox would be to completely draw it
yourself, basically copying the DrawCheck method from TCheckListbox.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, CheckLst;

type
TCheckListBox = Class( CheckLst.TCheckListbox )
protected
Procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
override;
end;

TForm1 = class(TForm)
CheckListBox1: TCheckListBox;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

{ TCheckListBox }

procedure TCheckListBox.DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState);
begin
If not (odSelected In State) Then
If Checked[ Index ] Then
Canvas.Brush.Color := clLime
Else
Canvas.Brush.Color := clYellow;
inherited;
end;

end.


Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!


0 new messages