Solved

Coloured rows in check list box

Posted on 2000-03-28
4
208 Views
Last Modified: 2010-08-05
I have a check list box component that displays a list of tasks to be completed.

I would like to be able to change the colour of a line if it has been active for more than 4 hours, but can't find a way to change 1 row's font attributes without changing every row.

Any ideas?
0
Comment
Question by:johnstoned
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:aubs
ID: 2663464
Use the ondrawitem event to change the font color for a particular line
0
 
LVL 2

Accepted Solution

by:
aubs earned 100 total points
ID: 2663502
Set the CheckListBox Style property to lbOwnerDrawFixed.


Then put this in the OnDrawItem Event. It should show you how you can change the font color.

procedure TMainForm.CheckListBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  Offset: integer;
begin
      with (Control as TCheckListBox).Canvas do
      begin
        Offset:= 6; //maynot be needed
            FillRect(Rect);
        if (Control as TCheckListBox).Checked[Index] then
              (Control as TCheckListBox).font.Color:= clRed
        else
          (Control as TCheckListBox).font.Color:= clBlack;
            TextOut(Rect.Left + Offset, Rect.Top, (Control as TCheckListBox).Items[Index]) ;
      end;

end;
0
 

Author Comment

by:johnstoned
ID: 2664425
This bit of code seemed to have a bug.  It keeps flashing the items up in the screen then redrawing them again.

if (Control as TCheckListBox).Checked[Index] then
   (Control as TCheckListBox).font.Color:= clRed
   else
     (Control as TCheckListBox).font.Color:= clBlack;


After a little experimentation, I changed

Control as TCheckListBox).font.Color:= clRed
to
font.Color:= clRed
and that seemed to cure it.

Thanks for the help.
0
 

Author Comment

by:johnstoned
ID: 2664426
This bit of code seemed to have a bug.  It keeps flashing the items up in the screen then redrawing them again.

if (Control as TCheckListBox).Checked[Index] then
   (Control as TCheckListBox).font.Color:= clRed
   else
     (Control as TCheckListBox).font.Color:= clBlack;


After a little experimentation, I changed

Control as TCheckListBox).font.Color:= clRed
to
font.Color:= clRed
and that seemed to cure it.

Thanks for the help.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now